MongoDB is a scalable, high-performance, open-source document database that provides dynamic queries and indexing. It aims to provide the power of relational databases with the scalability and flexibility of non-relational databases. Key features include ease of use, scaling capabilities, dynamic queries similar to SQL, and speed comparable to key-value stores while supporting rich querying like relational databases.
10. MongoDB
• Ease of use
• Scalable
• Dynamic queries - similar “feel” to SQL
• Speed of key/value stores (almost)
• Power of RDBMSs (almost)
11.
12. Downloading MongoDB
www.mongodb.org
Binaries available for Linux, Mac,
Windows, Solaris
13. The Venerable Java Driver
Available at Github:
www.github.com/mongodb/mongo-java-driver/downloads
JavaScript: { x : y, z : w }
Java: BasicDBObjectBuilder.start().add("x",
"y").add("z", "w").get()
14. Connecting to the Database
Mongo connection = new Mongo(“blog”);
DBCollection collection =
connection.getCollection(“posts”);
15. Inserting
collection.insert({
title : 'My first blog post',
author : 'Joe',
content : 'Hello, world!',
comments : []
});
16. Creating a User
DBObject post = BasicDBObjectBuilder.start()
.add("title", "My First Blog Post")
.add("username", "Joe")
.add("content", "Hello, world!")
.add("comments", new ArrayList())
.get();
collection.insert(post);
17. MongoDB::OID
an autogenerated primary key
collection.insert(post);
System.out.println(post.get("_id"));
--------------------------------------------
4a9700dba5f9107c5cbc9a9c