5. Document-Oriented
> db.users.insert( { _id : "alex", name: { first:"Alex", last:"Benisson" }, karma : 1.0 } )
> db.posts.findOne() {
_id : ObjectId("4e77bb3b8a3e000000004f7a"),
when : Date("2011-09-19T02:10:11.3Z",
author : "alex",
title : "No Free Lunch",
text : "This is the text of the post. It could be very long.",
tags : [ "business", "ramblings" ],
votes : 5,
voters : [ "jane", "joe", "spencer", "phyllis", "li" ],
comments : [
{ who : "jane", when : Date("2011-09-19T04:00:10.112Z"),
comment : "I agree." },
{ who : "meghan", when : Date("2011-09-20T14:36:06.958Z"),
comment : "You must be joking. etc etc ..." } ] }
6. Full-Index Support
> db.things.ensureIndex({j:1});
> db.things.ensureIndex({"address.city": 1})
> db.things.ensureIndex({j:1, name:-1});
> db.factories.insert( { name: "xyz", metro: { city: "New York", state: "NY" } } );
> db.factories.ensureIndex( { metro : 1 } ); // this query can use the above index: >
> db.factories.find( { metro: { city: "New York", state: "NY" } } );
// this one too, as {city:"New York"} < {city:"New York",state:"NY"}
> db.factories.find( { metro: { $gte : { city: "New York" } } } );
// this query does not match the document because the order of fields is significant
> db.factories.find( { metro: { state: "NY" , city: "New York" } } );
8. HA & FailOver
Only Write to Primary
Can read from Secondary
Op Ordinal:
Increasing ordinal to represent each operation
Using Server ID + Op Ordinal
9. Picking Primary
1. Get Max LocalOpOrdinal from each Server
2. if a majority of servers are not up (from
this server's POV), remain in Secondary
mode and stop.
3. if the last op time seems very old, stop
and await human intervention.
4. else, using a consensus protocol, pick the
server with the highest maxLocalOpOrdinal
as the Primary.
13. Use Lastest Version
2.0.2 is better than 1.8.x
MongoDB has global Lock
1.8.x uses global Write Lock
2.0.x uses write with yield.
Not supports db or collection lock