Benutzer:J.Ammon/MongoDB
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
- MTV Networks[54]
- craigslist[55]
- Disney Interactive Media Group[56]
- Wordnik[57]
- diaspora[58]
- Shutterfly[59]
- foursquare[60]
- bit.ly[61]
- The New York Times[62]
- SourceForge[63]
- Business Insider[64]
- Etsy[65]
- CERN LHC[66]
- Thumbtack[67]
- AppScale[68]
- Uber[69]
See also
References
- ↑ MongoDB Website
- ↑ MongoDB Blog - March 2010
- ↑ Geospatial indexes
- ↑ GridFS
- ↑ NGINX
- ↑ lighttpd
- ↑ capped collections
- ↑ [1]
- ↑ CentOS and Fedora
- ↑ Debian and Ubuntu,
- ↑ Gentoo
- ↑ Arch Linux
- ↑ official website
- ↑ [2]
- ↑ Schnittstelle für C
- ↑ Schnittstelle für C++
- ↑ a b Schnittstelle für C# Referenzfehler: Ungültiges
<ref>
-Tag. Der Name „csharp“ wurde mehrere Male mit einem unterschiedlichen Inhalt definiert. - ↑ Schnittstelle für Haskell
- ↑ Schnittstelle für Java
- ↑ Schnittstelle für JavaScript driver
- ↑ Schnittstelle für Lisp
- ↑ Schnittstelle für Perl
- ↑ Schnittstelle für PHP
- ↑ Schnittstelle für Python
- ↑ Schnittstelle für Ruby
- ↑ Casbah, die offiziell unterstützte Scala-Schnittstelle für MongoDB
- ↑ ColdFusion driver
- ↑ Delphi
- ↑ Emongo Erlang driver
- ↑ Erlmongo Erlang driver
- ↑ Factor driver
- ↑ Fantom driver
- ↑ gomongo Go driver
- ↑ GMongo
- ↑ JVM language center
- ↑ LuaMongo
- ↑ node.js driver
- ↑ REST interface
- ↑ rmongo
- ↑ [3]
- ↑ Smalltalk driver
- ↑ sharding
- ↑ [4]
- ↑ Munin plugin
- ↑ Ganglia plugin
- ↑ Scout slow-query plugin
- ↑ Cacti plugin
- ↑ Fang of Mongo
- ↑ Futon4Mongo
- ↑ Mongo3
- ↑ MongoHub
- ↑ Opricot
- ↑ The AGPL - MongoDB Blog: May 5, 2009
- ↑ MongoDB Powering MTV's Web Properties. 10. Mai 2011. Abgerufen am 6. Juli 2011.
- ↑ MongoDB live at craigslist. 16. Mai 2011. Abgerufen am 6. Juli 2011.
- ↑ Disney Central Services Storage: Leveraging Knowledge and skillsets. 24. Mai 2011. Abgerufen am 6. Juli 2011.
- ↑ 12 Months with MongoDB. 25. Oktober 2010. Abgerufen am 24. Mai 2011.
- ↑ MongoDB - diasporatest.com. 23. Dezember 2010. Abgerufen am 23. Dezember 2010.
- ↑ Implementing MongoDB at Shutterfly - Presentation at MongoSF. 30. April 2010. Abgerufen am 28. Juni 2010.
- ↑ MongoDB at foursquare - Presentation at MongoNYC. 21. Mai 2010. Abgerufen am 28. Juni 2010.
- ↑ bit.ly user history, auto-sharded - Presentation at MongoNYC. 21. Mai 2010. Abgerufen am 28. Juni 2010.
- ↑ Jacqueline Maher: Building a Better Submission Form, NYTimes Open Blog. 25. Mai 2010. Abgerufen am 28. Juni 2010.
- ↑ How Python, TurboGears, and MongoDB are Transforming SourceForge.net. PyCon 2010. 20. Februar 2010. Abgerufen am 28. Juni 2010.
- ↑ How This Web Site Uses MongoDB. Business Insider. 6. November 2010. Abgerufen am 28. Juni 2010.
- ↑ MongoDB at Etsy. Code as Craft: Etsy Developer Blog. 19. Mai 2010. Abgerufen am 28. Juni 2010. (Seite nicht mehr abrufbar)
- ↑ Holy Large Hadron Collider, Batman!. The MongoDB NoSQL Database Blog. 3. Juni 2010. Abgerufen am 3. August 2010.
- ↑ Building Our Own Tracking Engine With MongoDB. Thumbtack Blog. 3. Mai 2011. Abgerufen am 15. Mai 2011.
- ↑ http://appscale.cs.ucsb.edu/datastores.html#mongodb
- ↑ Node.js Meetup: Distributed Web Architectures – Curtis Chambers, Uber | JoyentCloud:. Abgerufen im 12 August 2011.
Bibliography
- MongoDB in Action, 1st edition, Manning, March 28, 2011, ISBN 9781935182870, pages 375
- MongoDB: The Definitive Guide, 1st edition, O'Reilly Media, September 23, 2010, ISBN 9781449381561, pages 216
- MongoDB for Web Development, 1st edition, Addison-Wesley Professional, March 3, 2011, ISBN 9780321705334, pages 360
- The Definitive Guide to MongoDB: The NoSQL Database for Cloud and Desktop Computing, 1st edition, Apress, September 26, 2010, ISBN 9781430230519, pages 350
External links
- Official MongoDB Project Website
- mongoDB User Group on LinkedIn
- MongoDB news and articles on myNoSQL
- Eric Lai. (2009, July 1). No to SQL? Anti-database movement gains steam
- MongoDB articles on NoSQLDatabases.com
- June 2009 San Francisco NOSQL Meetup Page
- Designing for the Cloud at MIT Technology Review
- EuroPython Conference Presentation
- Non-relational data persistence in Java using MongoDB - Software Engineer at MongoDB auf YouTube
- Interview with Mike Dirolf on The Changelog about MongoDB background and design decisions
- MongoMvc - A MongoDB Demo App with ASP.NET MVC
- FAQs about MongoDB
{{DEFAULTSORT:Mongodb}} [[Category:Open source database management systems]] [[Category:Document-oriented databases]] [[Category:Distributed computing architecture]] [[Category:Structured storage]] [[Category:NoSQL]]