Created
March 26, 2011 23:47
-
-
Save seanhess/888743 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
db.events.drop() | |
db.events.save({_id: "1", venue: "v1", act: "a1", dt: "2011-03-24 00:00"}) | |
db.events.save({_id: "2", venue: "v1", act: "a1", dt: "2011-03-25 00:00"}) | |
// the same act, playing at two venues at the same time? | |
db.events.save({_id: "3", venue: "v2", act: "a1", dt: "2011-03-23 00:00"}) | |
db.events.save({_id: "4", venue: "v2", act: "a1", dt: "2011-03-25 00:00"}) | |
// Another act playing at venue 1 | |
db.events.save({_id: "5", venue: "v1", act: "a2", dt: "2011-03-26 00:00"}) | |
db.events.save({_id: "6", venue: "v1", act: "a2", dt: "2011-03-27 00:00"}) | |
// | |
// db.events.ensureIndex({venue:1, act:1, dt: 1}) | |
// v1* a1* 24* | |
// v1* a1* 25 | |
// v1* a2 26 | |
// v1* a2 27 | |
// v2* a1* 23* | |
// v2* a1* 25 | |
// Q = v1,v2|a1|< | |
// db.events.ensureIndex({venue:1, dt: 1, act: 1}) | |
// db.events.ensureIndex({act:1, venue: 1, dt: 1}) | |
// db.events.ensureIndex({dt: 1, act:1, venue: 1}) | |
db.events.ensureIndex({act:1, dt: 1, venue: 1}) | |
// a1*, 23*, v2 | |
// a1*, 24, v1 | |
// a1*, 25, v1 | |
// a1*, 25, v2 | |
// a2, 26, v1 | |
// a2, 27, v1 | |
// db.events.ensureIndex({dt: 1, act:1, venue: 1}) | |
// 23*, a1*, v2* | |
// 24, a1*, v1* | |
// 25, a1*, v1* | |
// 25, a1*, v2* | |
// 26, a2, v1 | |
// 27, a2, v1 | |
var userVenues = ["v1", "v2"] | |
var topActs = ["a1", "a2"] | |
var now = "2011-03-20 00:00" | |
// when are the top acts playing next at any of my venues? | |
var results = db.events.find({act: "a1", venue: {$in: userVenues}, dt: {$gte: now}}) | |
.sort({dt:1}) | |
.limit(1) | |
// .toArray() | |
.explain() | |
printjson(results) | |
This file contains hidden or 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
{ | |
"cursor" : "BtreeCursor act_1_dt_1_venue_1 multi", | |
"nscanned" : 1, | |
"nscannedObjects" : 1, | |
"n" : 1, | |
"millis" : 0, | |
"indexBounds" : { | |
"act" : [ | |
[ | |
"a1", | |
"a1" | |
] | |
], | |
"dt" : [ | |
[ | |
"2011-03-20 00:00", | |
{ | |
} | |
] | |
], | |
"venue" : [ | |
[ | |
"v1", | |
"v1" | |
], | |
[ | |
"v2", | |
"v2" | |
] | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment