Jump to content

MongoDB: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Masterhomer (talk | contribs)
→‎Prominent users: - LHC -> CERN LHC
Line 193: Line 193:
* [[Business Insider]]<ref name="businessinsider">{{cite web|url=http://www.businessinsider.com/how-we-use-mongodb-2009-11 |title=How This Web Site Uses MongoDB |publisher=Business Insider |date=2010-11-06 |accessdate=2010-06-28}}</ref>
* [[Business Insider]]<ref name="businessinsider">{{cite web|url=http://www.businessinsider.com/how-we-use-mongodb-2009-11 |title=How This Web Site Uses MongoDB |publisher=Business Insider |date=2010-11-06 |accessdate=2010-06-28}}</ref>
* [[Etsy]]<ref name="etsy">{{cite web|url=http://codeascraft.etsy.com/2010/05/19/mongodb-at-etsy/ |title=MongoDB at Etsy |publisher=Code as Craft: Etsy Developer Blog |date=2010-05-19 |accessdate=2010-06-28}} {{Dead link|date=October 2010|bot=H3llBot}}</ref>
* [[Etsy]]<ref name="etsy">{{cite web|url=http://codeascraft.etsy.com/2010/05/19/mongodb-at-etsy/ |title=MongoDB at Etsy |publisher=Code as Craft: Etsy Developer Blog |date=2010-05-19 |accessdate=2010-06-28}} {{Dead link|date=October 2010|bot=H3llBot}}</ref>
* [[Large Hadron Collider|LHC]]<ref name="lhc">{{cite web|url=http://blog.mongodb.org/post/660037122/holy-large-hadron-collider-batman |title=Holy Large Hadron Collider, Batman! |publisher=The MongoDB NoSQL Database Blog |date=2010-06-03 |accessdate=2010-08-03}}</ref>
* [[Large Hadron Collider|CERN LHC]]<ref name="lhc">{{cite web|url=http://blog.mongodb.org/post/660037122/holy-large-hadron-collider-batman |title=Holy Large Hadron Collider, Batman! |publisher=The MongoDB NoSQL Database Blog |date=2010-06-03 |accessdate=2010-08-03}}</ref>
*[[Thumbtack (website)|Thumbtack]]<ref name="thumbtack">{{cite web|url=http://engineering.thumbtack.com/2011/05/03/building-our-own-tracking-engine-with-mongodb/|title=Building Our Own Tracking Engine With MongoDB|publisher=Thumbtack Blog|date=2011-05-03|accessdate=2011-05-15}}</ref>
*[[Thumbtack (website)|Thumbtack]]<ref name="thumbtack">{{cite web|url=http://engineering.thumbtack.com/2011/05/03/building-our-own-tracking-engine-with-mongodb/|title=Building Our Own Tracking Engine With MongoDB|publisher=Thumbtack Blog|date=2011-05-03|accessdate=2011-05-15}}</ref>
*[[AppScale]]<ref>http://appscale.cs.ucsb.edu/datastores.html#mongodb</ref>
*[[AppScale]]<ref>http://appscale.cs.ucsb.edu/datastores.html#mongodb</ref>

Revision as of 02:00, 27 July 2011

MongoDB
Developer(s)10gen
Initial release2009
Stable release
1.8.2 / June 18, 2011 (2011-06-18)
Repository
Written inC++
Operating systemCross-platform
Available inEnglish
TypeDocument-oriented database
LicenseGNU AGPL v3.0 (drivers: Apache license)
Websitehttp://www.mongodb.org/

MongoDB (from "humongous") is an open source, high-performance, schema-free, document-oriented database written in the C++ programming language.[1] The database is document-oriented so it manages collections of JSON-like documents. Many applications can thus model data in a more natural way, as data can be nested in complex hierarchies and still be query-able and indexable.

Development of MongoDB began in October 2007 by 10gen. The first public release was in February 2009.[2]

Features

Among the features are:

  • Consistent UTF-8 encoding. Non-UTF-8 data can be saved, queried, and retrieved with a special binary data type.
  • Cross-platform support: binaries are available for Windows, Linux, OS X, and Solaris. MongoDB can be compiled on almost any little-endian system.
  • Type-rich: supports dates, regular expressions, code, binary data, and more (all BSON types)
  • Cursors for query results

More features:

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.

Querying nested fields

Queries can "reach into" embedded objects and arrays. If the following object is inserted into the users collection:

   {
       "username" : "bob",
       "address" : {
           "street" : "123 Main Street",
           "city" : "Springfield",
           "state" : "NY"
       }
   }

We can query for this document (and all documents with an address in New York) with:

> db.users.find({"address.state" : "NY"})

Array elements can also be queried:

> db.food.insert({"fruit" : ["peach", "plum", "pear"]})
> db.food.find({"fruit" : "pear"})

Indexing

The software supports secondary indexes, including single-key, compound, unique, non-unique, and geospatial[3] 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.

Aggregation

In addition to ad hoc queries, the database supports a couple of tools for aggregation, including MapReduce[4] and a group function similar to SQL's GROUP BY.

File storage

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

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."

Capped collections

MongoDB supports fixed-size collections called capped collections.[8] 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,[9] 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.

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,[10] Debian and Ubuntu,[11] Gentoo[12] and Arch Linux.[13] It can also be acquired through the official website.[14]

MongoDB uses memory-mapped files, limiting data size to 2GB on 32-bit machines (64-bit systems have a much larger data size).[15] 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,[18] ColdFusion,[27] Delphi,[28] Erlang,[29][30] Factor,[31] Fantom,[32] Go,[33] JVM languages (Clojure, Groovy [34], Scala, etc.),[35] Lua,[36] node.js,[37] HTTP REST,[38] Ruby,[39] Racket,[40] and Smalltalk.[41]

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.

Example: starting a master/slave pair locally:

$ mkdir -p ~/dbs/master ~/dbs/slave
$ ./mongod --master --port 10000 --dbpath ~/dbs/master
$ ./mongod --slave --port 10001 --dbpath ~/dbs/slave --source localhost:10000

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

The developer's application must know that it is talking to a sharded cluster when performing some operations. For example, a "findAndModify" query must contain the shard key if the queried collection is sharded[43]. The application talks to a special routing process called `mongos` that looks identical to a single MongoDB server. This `mongos` process knows what data is on each shard and routes the client's requests appropriately. All requests flow through this process: it not only forwards requests and responses but also performs any necessary final data merges or sorts. Any number of `mongos` processes can be run: usually one per application server is recommended.

Management and graphical frontends

Official tools

The most powerful and useful management tool is the database shell, mongo. The 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.

Administrative information can also be accessed through the admin interface: a simple html 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 to help developers visualize their data. Some popular ones are:

  • Fang of Mongo[48] – a web-based UI built with Django and jQuery.
  • Futon4Mongo[49] – a clone of the CouchDB Futon web interface for MongoDB.
  • Mongo3[50] – a Ruby-based interface.
  • MongoHub[51] – a native OS X application for managing MongoDB.
  • Opricot[52] – a browser-based MongoDB shell written in PHP.
  • Database Master Windows based MongoDB Management Studio, supports also RDBMS.

Licensing and support

MongoDB is available for free under the GNU Affero General Public License. The language drivers are available under an Apache License.[53]

Prominent users

See also

References

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

Bibliography