Misplaced Pages

MongoDB: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 05:44, 9 February 2012 edit203.99.208.3 (talk) Dear Jasper Deng, you are putting SEVEN tags -- a note IS necessary. Learn how to tag pages← Previous edit Revision as of 05:58, 9 February 2012 edit undoJasper Deng (talk | contribs)Edit filter managers, Extended confirmed users, Pending changes reviewers, Rollbackers53,787 edits Undid revision 475892060 by 203.99.208.3 (talk)No, and that's an essay. I can't fix every one of these but I can't find valid criticism of this database software.Next edit →
Line 1: Line 1:
{{multiple issues|original research=January 2012|overly detailed=January 2012|technical=January 2012|refimprove = January 2012|advert = January 2012|peacock = January 2012|howto = October 2011}}

{{expert-subject|1=Computing|date=January 2012}}

{{Infobox software {{Infobox software
| name = General info | name = General info

Revision as of 05:58, 9 February 2012

This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)

No issues specified. Please specify issues, or remove this template.

(Learn how and when to remove this message)
This article needs attention from an expert in Computing. Please add a reason or a talk parameter to this template to explain the issue with the article. WikiProject Computing may be able to help recruit an expert. (January 2012)
General info
logo
Developer(s)10gen
Initial release2009
Stable release2.0.2 / December 14, 2011 (2011-12-14)
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 written in the C++ programming language. It manages collections of BSON documents.

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

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.
  • Cursors for query results

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.

Indexing

The software supports secondary indexes, including single-key, compound, unique, non-unique, and geospatial 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 and a group function similar to SQL's GROUP BY.

File storage

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

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; }, )

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. 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, 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, Debian and Ubuntu, Gentoo and Arch Linux. Also OS X Homebrew package manager includes MongoDB. It can also be acquired through the official website.

MongoDB uses memory-mapped files, limiting data size to 2GB on 32-bit machines (64-bit systems have a much larger data size). 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, ColdFusion, Delphi, Erlang, Factor, Fantom, Go, JVM languages (Clojure, Groovy, Scala, etc.), Lua, node.js, HTTP REST, Ruby, Racket, and Smalltalk.

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

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

Licensing and support

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

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

Bibliography

External links

Database management systems
Types
Concepts
Objects
Components
Functions
Related topics
Categories: