Skip to content

Instantly share code, notes, and snippets.

@gatesvp
Created March 4, 2011 00:58
Show Gist options
  • Select an option

  • Save gatesvp/853950 to your computer and use it in GitHub Desktop.

Select an option

Save gatesvp/853950 to your computer and use it in GitHub Desktop.
Method One: Array of Objects
------
var pd = { type: "Person", attributes: [{name: "Penelope Doe"},{age: 26}] };
var pd2 = { type: "Person", attributes: [ {name: "Johnny Doe"},{age: 27} ] };
db.foo.drop();
db.foo.save(pd);
db.foo.save(pd2);
db.foo.ensureIndex({attributes:1})
db.foo.find({'attributes' : {age : {$gt : 26 } } }).count()
db.foo.find({'attributes' : {age : {$gt : 26 } } }).explain()
{
"cursor" : "BtreeCursor attributes_1",
"nscanned" : 0,
"nscannedObjects" : 0,
"n" : 0,
"millis" : 1,
"indexBounds" : {
"attributes" : [
[
{
"age" : {
"$gt" : 26
}
},
{
"age" : {
"$gt" : 26
}
}
]
]
}
}
Method 2: Object
------
var pd = { type: "Person", attributes: { name: "Penelope Doe", age: 26 } };
var pd2 = { type: "Person", attributes: { name: "Johnny Doe", age: 27 } };
db.foo.drop();
db.foo.save(pd);
db.foo.save(pd2);
db.foo.ensureIndex({attributes:1})
db.foo.find({'attributes' : {age : {$gt : 26 } } }).count()
db.foo.find({'attributes' : {age : {$gt : 26 } } }).explain()
{
"cursor" : "BtreeCursor attributes_1",
"nscanned" : 0,
"nscannedObjects" : 0,
"n" : 0,
"millis" : 1,
"indexBounds" : {
"attributes" : [
[
{
"age" : {
"$gt" : 26
}
},
{
"age" : {
"$gt" : 26
}
}
]
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment