Last active
August 29, 2015 13:56
-
-
Save saml/8917660 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first inserting documents like: | |
db.businesses.insert({tags: ['A']}) | |
businesses@sam-HP-Z400> db.businesses.getIndexes() | |
[ | |
{ | |
"v" : 1, | |
"key" : { | |
"_id" : 1 | |
}, | |
"ns" : "businesses.businesses", | |
"name" : "_id_" | |
}, | |
{ | |
"v" : 1, | |
"key" : { | |
"tags" : 1 | |
}, | |
"ns" : "businesses.businesses", | |
"name" : "tags_1" | |
} | |
] | |
businesses@sam-HP-Z400> db.businesses.find({$and: [{tags: {$in: ['A']}}, {tags: {$in: ['C']}}]}).explain() | |
{ | |
"cursor" : "BtreeCursor tags_1", | |
"isMultiKey" : true, | |
"n" : 88, | |
"nscannedObjects" : 235, | |
"nscanned" : 235, | |
"nscannedObjectsAllPlans" : 235, | |
"nscannedAllPlans" : 235, | |
"scanAndOrder" : false, | |
"indexOnly" : false, | |
"nYields" : 0, | |
"nChunkSkips" : 0, | |
"millis" : 0, | |
"indexBounds" : { | |
"tags" : [ | |
[ | |
"A", | |
"A" | |
] | |
] | |
}, | |
"server" : "sam-HP-Z400:27017" | |
} | |
businesses@sam-HP-Z400> db.businesses.find({tags: ['C', 'A']}).explain() | |
{ | |
"cursor" : "BtreeCursor tags_1 multi", | |
"isMultiKey" : true, | |
"n" : 0, | |
"nscannedObjects" : 88, | |
"nscanned" : 89, | |
"nscannedObjectsAllPlans" : 88, | |
"nscannedAllPlans" : 89, | |
"scanAndOrder" : false, | |
"indexOnly" : false, | |
"nYields" : 0, | |
"nChunkSkips" : 0, | |
"millis" : 0, | |
"indexBounds" : { | |
"tags" : [ | |
[ | |
"C", | |
"C" | |
], | |
[ | |
[ | |
"C", | |
"A" | |
], | |
[ | |
"C", | |
"A" | |
] | |
] | |
] | |
}, | |
"server" : "sam-HP-Z400:27017" | |
} | |
businesses@sam-HP-Z400> db.businesses.find({$and: [{tags: {$in: ['C']}}, {tags: {$in: ['A']}}]}).explain() | |
{ | |
"cursor" : "BtreeCursor tags_1", | |
"isMultiKey" : true, | |
"n" : 88, | |
"nscannedObjects" : 88, | |
"nscanned" : 88, | |
"nscannedObjectsAllPlans" : 88, | |
"nscannedAllPlans" : 88, | |
"scanAndOrder" : false, | |
"indexOnly" : false, | |
"nYields" : 0, | |
"nChunkSkips" : 0, | |
"millis" : 0, | |
"indexBounds" : { | |
"tags" : [ | |
[ | |
"C", | |
"C" | |
] | |
] | |
}, | |
"server" : "sam-HP-Z400:27017" | |
} | |
then insert documents like: | |
db.businesses.insert({tags: {'A':1}}) | |
businesses@sam-HP-Z400> db.businesses.find({tags: {$all: ['A', 'C']}}).explain() | |
{ | |
"cursor" : "BtreeCursor tags_1", | |
"isMultiKey" : true, | |
"n" : 0, | |
"nscannedObjects" : 0, | |
"nscanned" : 0, | |
"nscannedObjectsAllPlans" : 0, | |
"nscannedAllPlans" : 0, | |
"scanAndOrder" : false, | |
"indexOnly" : false, | |
"nYields" : 0, | |
"nChunkSkips" : 0, | |
"millis" : 0, | |
"indexBounds" : { | |
"tags" : [ | |
[ | |
"A", | |
"A" | |
] | |
] | |
}, | |
"server" : "sam-HP-Z400:27017" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment