MongoDB

From Wikipedia, the free encyclopedia
Jump to: navigation, search
General info
logo
Developer(s) 10gen
Initial release 2009
Stable release 2.0.2 / December 14, 2011; 2 months ago (2011-12-14)
Development status Active
Written in C++
Operating system Cross-platform
Available in English
Type Document-oriented database
License GNU AGPL v3.0 (drivers: Apache license)
Website www.mongodb.org

MongoDB (from "humongous") is an open source document-oriented NoSQL database system written in the C++ programming language.[1] It manages collections of BSON documents.

Development of MongoDB began in October 2007 by 10gen. The first public release was in February 2009.[2] Binaries are available for Windows, Linux, OS X, and Solaris.[3]

Contents

[edit] History

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

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).[5][6]

[edit] Features

[edit] Ad hoc queries

In MongoDB, any field can be queried at any time. MongoDB supports range queries, regular expression searches, and other special types of queries in addition to exactly matching fields. Queries can also include user-defined JavaScript functions (if the function returns true, the document matches).

Queries can return specific fields of documents (instead of the entire document), as well as sorting, skipping, and limiting results. Queries can "reach into" embedded objects and arrays.

[edit] Indexing

Indexes in MongoDB are conceptually similar to those in RDBMSes like MySQL. Any field in a MongoDB document can be indexed.[7]

Secondary indexes are also available, including single-key, compound, unique, non-unique, and geospatial[8] indexes. Nested fields (as described above in the ad hoc query section) can also be indexed and indexing an array type will index each element of the array.

MongoDB's query optimizer will try a number of different query plans when a query is run and select the fastest, periodically resampling. Developers can see the index being used with the `explain` function and choose a different index with the `hint` function.

Indexes can be created or removed at any time.

[edit] Aggregation

In addition to ad hoc queries, MapReduce[9] can be used for batch processing of data and aggregation operations. In version 2.1, the current development release of MongoDB, a new aggregation framework is available. This framework enables users to obtain the kind of results SQL group-by is used for, without having to write custom JavaScript.[10]

[edit] File storage

The software implements a protocol called GridFS[11] that is used to store and retrieve files from the database. This file storage mechanism has been used in plugins for NGINX[12] and lighttpd.[13]

[edit] Server-side JavaScript execution

JavaScript is the lingua franca of MongoDB and can be used in queries, aggregation functions (such as MapReduce), and sent directly to the database to be executed.

Example of JavaScript in a query:

> db.foo.find({$where : function() { return this.x == this.y; }})

Example of code sent to the database to be executed:

> db.eval(function(name) { return "Hello, "+name; }, ["Joe"])

This returns "Hello, Joe".

JavaScript variables can also be stored in the database and used by any other JavaScript as a global variable. Any legal JavaScript type, including functions and objects, can be stored in MongoDB so that JavaScript can be used to write "stored procedures."

[edit] Capped collections

MongoDB supports fixed-size collections called capped collections.[14] A capped collection is created with a set size and, optionally, number of elements. Capped collections are the only type of collection that maintains insertion order: once the specified size has been reached, a capped collection behaves like a circular queue.

A special type of cursor, called a tailable cursor,[15] can be used with capped collections. This cursor was named after the `tail -f` command, and does not close when it finishes returning results but continues to wait for more to be returned, returning new results as they are inserted into the capped collection.

[edit] 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,[16] Debian and Ubuntu,[17] Gentoo[18] and Arch Linux.[19] Also OS X Homebrew package manager includes MongoDB.[20] It can also be acquired through the official website.[21]

MongoDB uses memory-mapped files, limiting data size to 2GB on 32-bit machines (64-bit systems have a much larger data size).[22] 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.

[edit] Language support

MongoDB has official drivers for:

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

[edit] 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.

[edit] Master-slave

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

[edit] 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.

[edit] Sharding

MongoDB scales horizontally using a system called sharding[51] 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.)

[edit] Management and graphical frontends

[edit] 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.[52]

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.

[edit] Monitoring

There are monitoring plugins available for MongoDB:

[edit] GUIs

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

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

[edit] Licensing and support

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

[edit] 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.

[edit] Prominent users

[edit] See also

[edit] References

  1. ^ MongoDB website
  2. ^ a b MongoDB Blog - March 2010
  3. ^ http://www.mongodb.org/downloads
  4. ^ http://www.theregister.co.uk/2011/05/25/the_once_and_future_mongodb/
  5. ^ http://www.10gen.com/what-is-mongodb
  6. ^ http://www.mongodb.org/display/DOCS/Philosophy
  7. ^ http://www.mongodb.org/display/DOCS/Indexes
  8. ^ Geospatial indexes
  9. ^ MapReduce
  10. ^ http://blog.mongodb.org/post/16015854270/operations-in-the-new-aggregation-framework
  11. ^ GridFS
  12. ^ NGINX
  13. ^ lighttpd
  14. ^ capped collections
  15. ^ [1]
  16. ^ CentOS and Fedora
  17. ^ Debian and Ubuntu,
  18. ^ Gentoo
  19. ^ Arch Linux
  20. ^ [2]
  21. ^ official website
  22. ^ [3]
  23. ^ C driver
  24. ^ C++ driver
  25. ^ a b C# driver
  26. ^ Erlang driver
  27. ^ Haskell driver
  28. ^ Java driver
  29. ^ JavaScript driver
  30. ^ [4]
  31. ^ Perl driver
  32. ^ PHP driver
  33. ^ Python driver
  34. ^ Ruby driver
  35. ^ Casbah, the officially supported Scala Driver for MongoDB
  36. ^ ColdFusion driver
  37. ^ Delphi
  38. ^ Emongo Erlang driver
  39. ^ Erlmongo Erlang driver
  40. ^ Factor driver
  41. ^ Fantom driver
  42. ^ gomongo Go driver
  43. ^ GMongo
  44. ^ JVM language center
  45. ^ LuaMongo
  46. ^ node.js driver
  47. ^ REST interface
  48. ^ rmongo
  49. ^ [5]
  50. ^ Smalltalk driver
  51. ^ sharding
  52. ^ http://www.mongodb.org/display/DOCS/mongo+-+The+Interactive+Shell
  53. ^ Munin plugin
  54. ^ Ganglia plugin
  55. ^ Scout slow-query plugin
  56. ^ Cacti plugin
  57. ^ phpMoAdmin
  58. ^ Fang of Mongo
  59. ^ Futon4Mongo
  60. ^ JMongoBrowser
  61. ^ Mongo3
  62. ^ MongoHub
  63. ^ Opricot
  64. ^ The AGPL - MongoDB Blog: May 5, 2009
  65. ^ http://www.10gen.com/commercial-licenses
  66. ^ "MongoDB Powering MTV's Web Properties". 2011-05-10. http://blog.mongodb.org/post/5360007734/mongodb-powering-mtvs-web-properties. Retrieved 2011-07-06. 
  67. ^ "MongoDB live at craigslist". 2011-05-16. http://blog.mongodb.org/post/5545198613/mongodb-live-at-craigslist. Retrieved 2011-07-06. 
  68. ^ "Disney Central Services Storage: Leveraging Knowledge and skillsets". 2011-05-24. http://www.10gen.com/presentation/mongosf2011/disney. Retrieved 2011-07-06. 
  69. ^ "12 Months with MongoDB". 2010-10-25. http://blog.wordnik.com/12-months-with-mongodb. Retrieved 2011-05-24. 
  70. ^ "MongoDB - diasporatest.com". 2010-12-23. http://www.diasporatest.com/index.php/MongoDB. Retrieved 2010-12-23. 
  71. ^ "Implementing MongoDB at Shutterfly - Presentation at MongoSF". 2010-04-30. http://www.10gen.com/event_mongosf_10apr30#shutterfly. Retrieved 2010-06-28. 
  72. ^ "MongoDB at foursquare - Presentation at MongoNYC". 2010-05-21. http://blip.tv/file/3704098. Retrieved 2010-06-28. 
  73. ^ "bit.ly user history, auto-sharded - Presentation at MongoNYC". 2010-05-21. http://blip.tv/file/3704043. Retrieved 2010-06-28. 
  74. ^ Maher, Jacqueline (2010-05-25). "Building a Better Submission Form". NYTimes Open Blog. http://open.blogs.nytimes.com/2010/05/25/building-a-better-submission-form/. Retrieved 2010-06-28. 
  75. ^ "How Python, TurboGears, and MongoDB are Transforming SourceForge.net". PyCon 2010. 2010-02-20. http://us.pycon.org/2010/conference/schedule/event/110/. Retrieved 2010-06-28. 
  76. ^ "How This Web Site Uses MongoDB". Business Insider. 2010-11-06. http://www.businessinsider.com/how-we-use-mongodb-2009-11. Retrieved 2010-06-28. 
  77. ^ "MongoDB at Etsy". Code as Craft: Etsy Developer Blog. 2010-05-19. http://codeascraft.etsy.com/2010/05/19/mongodb-at-etsy/. Retrieved 2010-06-28. 
  78. ^ "Holy Large Hadron Collider, Batman!". The MongoDB NoSQL Database Blog. 2010-06-03. http://blog.mongodb.org/post/660037122/holy-large-hadron-collider-batman. Retrieved 2010-08-03. 
  79. ^ "Building Our Own Tracking Engine With MongoDB". Thumbtack Blog. 2011-05-03. http://engineering.thumbtack.com/2011/05/03/building-our-own-tracking-engine-with-mongodb/. Retrieved 2011-05-15. 
  80. ^ http://appscale.cs.ucsb.edu/datastores.html#mongodb
  81. ^ "Node.js Meetup: Distributed Web Architectures – Curtis Chambers, Uber | JoyentCloud:". http://www.joyentcloud.com/resources/videos/node-js-office-hours-curtis-chambers-uber/. Retrieved 12 August 2011. 
  82. ^ www.infoq.com/presentations/Why-I-Chose-MongoDB-for-Guardian

[edit] Bibliography

[edit] External links

Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages