Jump to content

MongoDB: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Ciges (talk | contribs)
Features: Removed misplaced </ref> tag under the "Indexing" header
Line 49: Line 49:
:MongoDB supports search by field, range queries, regular expression searches. Queries can return specific fields of documents and also include <u>user-defined JavaScript functions</u>.
:MongoDB supports search by field, range queries, regular expression searches. Queries can return specific fields of documents and also include <u>user-defined JavaScript functions</u>.
;Indexing
;Indexing
:Any field in a MongoDB document can be indexed (indexes in MongoDB are conceptually similar to those in RDBMSes). Secondary indexes are also available</ref>.
:Any field in a MongoDB document can be indexed (indexes in MongoDB are conceptually similar to those in RDBMSes). Secondary indexes are also available.
;Aggregation
;Aggregation
:[[MapReduce]] can be used for batch processing of data and aggregation operations. The aggregation framework enables users to obtain the kind of results SQL group-by is used for
:[[MapReduce]] can be used for batch processing of data and aggregation operations. The aggregation framework enables users to obtain the kind of results SQL group-by is used for

Revision as of 14:11, 7 March 2012

General info
Developer(s)10gen
Initial release2009
Stable release
2.0.3 / February 27, 2012 (2012-02-27)
Repository
Written inC++
Operating systemCross-platform
Available inEnglish
TypeDocument-oriented database
LicenseGNU AGPL v3.0 (drivers: Apache license)
Websitewww.mongodb.org

MongoDB (from "humongous") is an open source document-oriented NoSQL database system.

MongoDB makes part of the "new" NoSQL family of database systems. Instead of storing data in tables as is made in a "classical" relational database, MongoDB store structure data as JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making easier and faster the integration of data in certain type of applications.

Development of MongoDB began in October 2007 by 10gen. It is now a mature and feature rich database ready for production use. It's used, by example, by MTV Networks[1], Craigslist[2] or Foursquare[3].

The goal of the MongoDB project is to bridge the gap between key-value stores (which are highly scalable) and relational databases (which have rich functionality).[4][5]

Binaries are available for Windows, Linux, OS X, and Solaris.[6]

History

Development of MongoDB began at 10gen in 2007, when the company was building a Platform as a Service similar to Google App Engine.[7]. In 2009 MongoDB was open sourced as a stand-alone product.[8], with an AGPL license.

In March 2011, from version 1.4, MongoDB has been considered production ready[9].

The last stable version (in March 2012) is 2.0.3, released in February 2012.

Features

A summary of main features could be the following

Ad hoc queries
MongoDB supports search by field, range queries, regular expression searches. Queries can return specific fields of documents and also include user-defined JavaScript functions.
Indexing
Any field in a MongoDB document can be indexed (indexes in MongoDB are conceptually similar to those in RDBMSes). Secondary indexes are also available.
Aggregation
MapReduce can be used for batch processing of data and aggregation operations. The aggregation framework enables users to obtain the kind of results SQL group-by is used for
File storage
The software implements a protocol called GridFS[10] that is used to store and retrieve files from the database (used, by example, in plugins for NGINX[11] and lighttpd.[12])
Server-side JavaScript execution
JavaScript can be used in queries, aggregation functions (such as MapReduce), are sent directly to the database to be executed.
Capped collections
MongoDB supports fixed-size collections called capped collections. This type of collection maintains insertion order and, once the specified size has been reached, behaves like a circular queue.


For further information on the points listed look up the MongoDB Developer Manual

Data manipulation

Collections and Documents

MongoDB store structure data as JSON-like documents with dynamic schemas (called BSON), with no predefined schema.

The element of data is called documents, stored in collections. One collection may have any number of documents.

Compared to relational databases we could say collections are as tables, and documents are as records. But there is one big difference: every record in a table have the same number of fields, while documents in a collection could have completely different fields.

One table SQL could be represented as

Last Name First Name Age
DUMONT Jean 43
PELLERIN Franck 29
MATTHIEU Nicolas 51
Every record in a SQL table a the same fields

However a MongoDB collection could be described as

{
"_id": ObjectId("4efa8d2b7d284dad101e4bc9"),
"Last Name": "DUMON",
"First Name": "Jean",
"Age": 43
},

{
"_id": ObjectId("4efa8d2b7d284dad101e4bc7"),
"Last Name":  "PELLERIN",
"First Name": "Franck",
"Age": 29,
"Address": "1 chemin des Loges",
"City": "VERSAILLES"
}
Documents in a MongoDB collection could have different fields (note: "_id" field is obligatory, automatically created by MongoDB, it's an unique index which identify the document

In a document, new fields could be added, existing ones suppressed, modified or renamed at any moment. There is no predefined schema. A document structure is really simple and composed of key-value pairs like associative arrays in programming languages (following the JSON format). The key is the field name, the value is its content. Both are separated by ":", as in the example shown.

As value we could use numbers, strings and also binary data like images or another key-value pairs as in the following example:

{
"_id": ObjectId("4efa8d2b7d284dad101e4bc7"),
"Last Name": "PELLERIN",
"First Name ": "Franck",
"Age": 29,
"Address": 
     {
      "Street" : "1 chemin des Loges",
      "City": "VERSAILLES"
     }
}

Here we can see that the field "Address" contains another document with two fields "Street" and "City".

Deployment

MongoDB can be built and installed from source, but it is more commonly installed from a binary package. Many Linux package management systems now include a MongoDB package, including CentOS and Fedora,[13] Debian and Ubuntu,[14] Gentoo[15] and Arch Linux.[16] Also OS X Homebrew package manager includes MongoDB.[17] It can also be acquired through the official website.[18]

MongoDB uses memory-mapped files, limiting data size to 2GB on 32-bit machines (64-bit systems have a much larger data size).[19] The MongoDB server can only be used on little-endian systems, although most of the drivers work on both little-endian and big-endian systems.

Language support

MongoDB has official drivers for:

There are also a large number of unofficial drivers, for C# and .NET,[22] ColdFusion,[33] Delphi,[34] Erlang,[35][36] Factor,[37] Fantom,[38] Go,[39] JVM languages (Clojure, Groovy,[40] Scala, etc.),[41] Lua,[42] node.js,[43] HTTP REST,[44] Ruby,[45] Racket,[46] and Smalltalk.[47]

Replication

MongoDB supports master-slave replication. A master can perform reads and writes. A slave copies data from the master and can only be used for reads or backup (not writes).

MongoDB allows developers to guarantee that an operation has been replicated to at least N servers on a per-operation basis.

Master-slave

As operations are performed on the master, the slave will replicate any changes to the data.

Replica sets

Replica sets are similar to master-slave, but they incorporate the ability for the slaves to elect a new master if the current one goes down.

Sharding

MongoDB scales horizontally using a system called sharding[48] which is very similar to the BigTable and PNUTS scaling model. The developer chooses a shard key, which determines how the data in a collection will be distributed. The data is split into ranges (based on the shard key) and distributed across multiple shards. (A shard is a master with one or more slaves.)

Management and graphical frontends

Official tools

The database shell lets developers view, insert, remove, and update data in their databases, as well as get replication information, setting up sharding, shut down servers, execute JavaScript, and more. mongo is built on SpiderMonkey, so it is a full JavaScript shell as well as being able to connect to MongoDB servers.[49]

Administrative information can also be accessed through the web interface a simple webpage that serves information about the current server status. By default, this interface is 1000 ports above the database port (http://localhost:28017) and it can be turned off with the --norest option.

mongostat is a command-line tool that displays a simple list of stats about the last second: how many inserts, updates, removes, queries, and commands were performed, as well as what percentage of the time the database was locked and how much memory it is using.

mongosniff sniffs network traffic going to and from MongoDB.

Monitoring

There are monitoring plugins available for MongoDB:

GUIs

Several GUIs have been created by MongoDB's developer community to help visualize their data. Some popular ones are:

  • phpMoAdmin[54] - a full-featured PHP GUI that runs entirely from a single 95kb self-configuring file, built over the Vork Enterprise Framework
  • Fang of Mongo[55] – a web-based UI built with Django and jQuery.
  • Futon4Mongo[56] – a clone of the CouchDB Futon web interface for MongoDB.
  • JMongoBrowser[57] – a desktop application for all platforms.
  • Mongo3[58] – a Ruby-based interface.
  • MongoHub[59] – a native Mac OS X application for managing MongoDB.
  • Opricot[60] – a browser-based MongoDB shell written in PHP.
  • Database Master - MongoDB Management Tool - Supports also RDBMS like: Oracle, SQLServer, MySQL
  • BI Studio - Business Intelligence Software for RDBMS and MongoDB.

Licensing and support

MongoDB is available for free under the GNU Affero General Public License. The language drivers are available under an Apache License.[61] In addition, 10gen offers commercial licenses for MongoDB.[62]

Epoch Issues

Objects in MongoDB are assigned an ObjectID, which incorporates a 32 bit representation of time in seconds since epoch (which in computers is typically seconds since the start of 1970), and another 64 bits containing a 24 bit machine id, 16 bit process id, and a 24 bit counter. As with all fixed size representations of time, this is susceptible to rollover, specifically the Year 2038 problem. Applications built upon mongo that make use of the embedded time representation contained within the ObjectID would misinterpret dates even though MongoDB itself would continue to function.

Prominent users

See also

References

  1. ^ a b "MongoDB Powering MTV's Web Properties". 2011-05-10. Retrieved 2011-07-06.
  2. ^ a b "MongoDB live at craigslist". 2011-05-16. Retrieved 2011-07-06.
  3. ^ a b "MongoDB at foursquare - Presentation at MongoNYC". 2010-05-21. Retrieved 2010-06-28.
  4. ^ http://www.10gen.com/what-is-mongodb
  5. ^ http://www.mongodb.org/display/DOCS/Philosophy
  6. ^ http://www.mongodb.org/downloads
  7. ^ MongoDB daddy: My baby beats Google BigTable
  8. ^ The MongoDB NoSQL Database Blog, The AGPL
  9. ^ The MongoDB NoSQL Database Blog, MongoDB 1.4 Ready for Production
  10. ^ GridFS
  11. ^ NGINX
  12. ^ lighttpd
  13. ^ CentOS and Fedora
  14. ^ Debian and Ubuntu,
  15. ^ Gentoo
  16. ^ Arch Linux
  17. ^ [1]
  18. ^ official website
  19. ^ [2]
  20. ^ C driver
  21. ^ C++ driver
  22. ^ a b C# driver Cite error: The named reference "csharp" was defined multiple times with different content (see the help page).
  23. ^ Erlang driver
  24. ^ Haskell driver
  25. ^ Java driver
  26. ^ JavaScript driver
  27. ^ [3]
  28. ^ Perl driver
  29. ^ PHP driver
  30. ^ Python driver
  31. ^ Ruby driver
  32. ^ Casbah, the officially supported Scala Driver for MongoDB
  33. ^ ColdFusion driver
  34. ^ Delphi
  35. ^ Emongo Erlang driver
  36. ^ Erlmongo Erlang driver
  37. ^ Factor driver
  38. ^ Fantom driver
  39. ^ gomongo Go driver
  40. ^ GMongo
  41. ^ JVM language center
  42. ^ LuaMongo
  43. ^ node.js driver
  44. ^ REST interface
  45. ^ rmongo
  46. ^ [4]
  47. ^ Smalltalk driver
  48. ^ sharding
  49. ^ http://www.mongodb.org/display/DOCS/mongo+-+The+Interactive+Shell
  50. ^ Munin plugin
  51. ^ Ganglia plugin
  52. ^ Scout slow-query plugin
  53. ^ Cacti plugin
  54. ^ phpMoAdmin
  55. ^ Fang of Mongo
  56. ^ Futon4Mongo
  57. ^ JMongoBrowser
  58. ^ Mongo3
  59. ^ MongoHub
  60. ^ Opricot
  61. ^ The AGPL - MongoDB Blog: May 5, 2009
  62. ^ http://www.10gen.com/commercial-licenses
  63. ^ "Disney Central Services Storage: Leveraging Knowledge and skillsets". 2011-05-24. Retrieved 2011-07-06.
  64. ^ "12 Months with MongoDB". 2010-10-25. Retrieved 2011-05-24.
  65. ^ "MongoDB - diasporatest.com". 2010-12-23. Retrieved 2010-12-23.
  66. ^ "Implementing MongoDB at Shutterfly - Presentation at MongoSF". 2010-04-30. Retrieved 2010-06-28.
  67. ^ "bit.ly user history, auto-sharded - Presentation at MongoNYC". 2010-05-21. Retrieved 2010-06-28.
  68. ^ Maher, Jacqueline (2010-05-25). "Building a Better Submission Form". NYTimes Open Blog. Retrieved 2010-06-28.
  69. ^ "How Python, TurboGears, and MongoDB are Transforming SourceForge.net". PyCon 2010. 2010-02-20. Retrieved 2010-06-28.
  70. ^ "How This Web Site Uses MongoDB". Business Insider. 2010-11-06. Retrieved 2010-06-28.
  71. ^ "MongoDB at Etsy". Code as Craft: Etsy Developer Blog. 2010-05-19. Retrieved 2010-06-28.
  72. ^ "Holy Large Hadron Collider, Batman!". The MongoDB NoSQL Database Blog. 2010-06-03. Retrieved 2010-08-03.
  73. ^ "Building Our Own Tracking Engine With MongoDB". Thumbtack Blog. 2011-05-03. Retrieved 2011-05-15.
  74. ^ http://appscale.cs.ucsb.edu/datastores.html#mongodb
  75. ^ "Node.js Meetup: Distributed Web Architectures – Curtis Chambers, Uber | JoyentCloud:". Retrieved 12 August 2011.
  76. ^ www.infoq.com/presentations/Why-I-Chose-MongoDB-for-Guardian

Bibliography