Benutzer:J.Ammon/MongoDB

aus Wikipedia, der freien Enzyklopädie
MongoDB
Basisdaten

Entwickler 10gen
Aktuelle Version 1.8.3
(22. August 2011)
Betriebssystem Cross-platform
Programmiersprache C++
Kategorie Dokumentenorientierte Datenbank
Lizenz GNU AGPL v3.0 (drivers: Apache license)
deutschsprachig nein
http://www.mongodb.org/

MongoDB (von englisch "humongous" = "riesig, gigantisch") ist eine dokumentenorientierte Datenbank. Die Datenbank ist schemalos, mit hoher Performance, der in C++ geschriebene Quellcode liegt als Open Source vor.[1] Als dokumentenorientierte Datenbank verarbeitet sie JSON-artige Dokumente. So können viele Anwendungen ihre Daten auf viel natürlichere Art modellieren. Die Daten können komplexe Hierarchien abbilden und trotzdem abgefragt und indexiert werden.

Die Entwicklung von MongoDB wurde im Oktober 2007 von 10gen begonnen. Der erste öffentliche Release war im Februar 2009.[2]

Features

  • Durchgehende Verwendung von UTF-8. Nicht-UTF-8-Daten können mit Hilfe eines speziellen binären Datentyps gespeichert und abgefragt werden.
  • Unterstützung aller gängigen Betriebssysteme: Ausführbare Dateien stehen für Windows, Linux, OS X und Solaris zur Verfügung. MongoDB kann auf fast jedem System mit "little-endian" Byte-Reihenfolge kompiliert werden.
  • Breite Unterstützung von Datentypen wie Datum, Reguläre Ausdrücke, Code, Binärdaten und andere (alle BSON-Datentypen).
  • Cursors für Abfrageergebnisse.

Weitere Features:

Ad-hoc-Abfragen

In MongoDB können jederzeit Abfragen auf jedes Datenfeld gemacht werden, d.h. man ist nicht auf vorbereitete Abfragen beschränkt. MongoDB unterstützt nicht nur Abfragen nach exakt passenden Daten, sondern auch nach Zahlenbereichen, regulären Ausdrücken und andere spezialisierte Abfragen. Abfragen können auch selbst-definierte JavaScript-Funktionen beinhalten (wenn die Funktion "true" zurücklieferte, wird das Dokument gefunden).

Abfragen können nicht nur ganze Dokumente, sondern auch einzelne Felder liefern, die Ergebnisse können sortiert oder auf eine vorgegebene Anzahl begrenzt werden.

Abfragen auf verschachtelte Felder

Abfragen können sich nicht nur auf Felder der Dokumente, sondern auch auf Felder der eingebetteten Objekte oder Arrays beziehen. Wenn das folgende JSON-Objekt

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

in die Datenbank users eingefügt wird, kann man so nach Adressen in New York suchen:

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

Auch Elemente von Arrays koennen abgefragt werden:

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

Indizes

Die Software unterstützt zusätzliche Indizes, einfache und zusammengesetzte, unique und nicht-unique sowie Indizes für Geodaten[3]. Verschachtelte Felder können (wie oben beschrieben) ebenfalls indiziert werden. Ein Index auf einen Array-Typ indiziert jedes Element des Arrays.

Der "query optimizer" von MongoDB versucht bei einer Abfrage verschiedene Abfragewege und wählt den schnellsten aus. Entwickler können mit der `explain`-Funktion sich die verwendeten Indizes anzeigen lassen und mit dr `hint`-Funktion andere Indices für die Abfrage vorgeben.

Indizes können jederzeit erstellt und gelöscht werden.

Aggregation

Zusätzlich zu normalen Abfragen unterstützt MongoDB Aggregationsfunktionen wie Map-Reduce und Funktionen zur Gruppierung entsprechend der SQL-Funktion "GROUP BY".

Speichern großer Dateien

MongoDB-Dokumente können bis zu 16 GB (in älteren Implementierungen 4 GB) groß werden. Zum Speichern größerer Dateien implementiert die Software ein Protokoll namens GridFS[4]. Dieser Mechanismus wird auch genutzt, um große Dateien in verschiedenen Dokumenten zu referenzieren, aber nur einmal zu speichern. Er erlaubt (z.B. für Videos) auch das Abrufen von Teilen der Datei (z.B. die ersten n MB). Dieser Dateispeichermechanismus wird auch in Plugins für nginx[5] and lighttpd[6] benutzt.

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

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

Unterstützte Programmiersprachen

MongoDB hat offiziell unterstützte Schnittstellen für: C[15], C++[16], C#[17], Haskell[18], Java[19], JavaScript[20], Lisp[21], Perl[22], PHP[23], Python[24], Ruby[25] und Scala[26].

There are also a large number of unofficial drivers, for C# and .NET,[17] 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

Portal: Free software – Übersicht zu Wikipedia-Inhalten zum Thema Free software

References

  1. MongoDB Website
  2. MongoDB Blog - March 2010
  3. Geospatial indexes
  4. GridFS
  5. NGINX
  6. lighttpd
  7. capped collections
  8. [1]
  9. CentOS and Fedora
  10. Debian and Ubuntu,
  11. Gentoo
  12. Arch Linux
  13. official website
  14. [2]
  15. Schnittstelle für C
  16. Schnittstelle für C++
  17. a b Schnittstelle für C# Referenzfehler: Ungültiges <ref>-Tag. Der Name „csharp“ wurde mehrere Male mit einem unterschiedlichen Inhalt definiert.
  18. Schnittstelle für Haskell
  19. Schnittstelle für Java
  20. Schnittstelle für JavaScript driver
  21. Schnittstelle für Lisp
  22. Schnittstelle für Perl
  23. Schnittstelle für PHP
  24. Schnittstelle für Python
  25. Schnittstelle für Ruby
  26. Casbah, die offiziell unterstützte Scala-Schnittstelle für 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. 10. Mai 2011. Abgerufen am 6. Juli 2011.
  55. MongoDB live at craigslist. 16. Mai 2011. Abgerufen am 6. Juli 2011.
  56. Disney Central Services Storage: Leveraging Knowledge and skillsets. 24. Mai 2011. Abgerufen am 6. Juli 2011.
  57. 12 Months with MongoDB. 25. Oktober 2010. Abgerufen am 24. Mai 2011.
  58. MongoDB - diasporatest.com. 23. Dezember 2010. Abgerufen am 23. Dezember 2010.
  59. Implementing MongoDB at Shutterfly - Presentation at MongoSF. 30. April 2010. Abgerufen am 28. Juni 2010.
  60. MongoDB at foursquare - Presentation at MongoNYC. 21. Mai 2010. Abgerufen am 28. Juni 2010.
  61. bit.ly user history, auto-sharded - Presentation at MongoNYC. 21. Mai 2010. Abgerufen am 28. Juni 2010.
  62. Jacqueline Maher: Building a Better Submission Form, NYTimes Open Blog. 25. Mai 2010. Abgerufen am 28. Juni 2010. 
  63. How Python, TurboGears, and MongoDB are Transforming SourceForge.net. PyCon 2010. 20. Februar 2010. Abgerufen am 28. Juni 2010.
  64. How This Web Site Uses MongoDB. Business Insider. 6. November 2010. Abgerufen am 28. Juni 2010.
  65. MongoDB at Etsy. Code as Craft: Etsy Developer Blog. 19. Mai 2010. Abgerufen am 28. Juni 2010. (Seite nicht mehr abrufbar)
  66. Holy Large Hadron Collider, Batman!. The MongoDB NoSQL Database Blog. 3. Juni 2010. Abgerufen am 3. August 2010.
  67. Building Our Own Tracking Engine With MongoDB. Thumbtack Blog. 3. Mai 2011. Abgerufen am 15. Mai 2011.
  68. http://appscale.cs.ucsb.edu/datastores.html#mongodb
  69. Node.js Meetup: Distributed Web Architectures – Curtis Chambers, Uber | JoyentCloud:. Abgerufen im 12 August 2011.

Bibliography

Vorlage:Refbegin

Vorlage:Refend

External links

{{DEFAULTSORT:Mongodb}} [[Category:Open source database management systems]] [[Category:Document-oriented databases]] [[Category:Distributed computing architecture]] [[Category:Structured storage]] [[Category:NoSQL]]