Skip to content

Instantly share code, notes, and snippets.

@scotthernandez
Created April 16, 2014 18:41
Show Gist options
  • Save scotthernandez/10918833 to your computer and use it in GitHub Desktop.
Save scotthernandez/10918833 to your computer and use it in GitHub Desktop.
var st = new ShardingTest({nodes:2})
db = st.s0.getDB("test")
sh.enableSharding("test")
sh.shardCollection("test.Listings")
sh.shardCollection("test.Listings", {_id:"hashed"})
db.Listings.insert([
{ "_id" : 1, "location" : { "type" : "Point", "coordinates" : [ 0, 0 ] } },
{ "_id" : 2, "location" : { "type" : "Point", "coordinates" : [ 1, 1 ] } },
{ "_id" : 3, "location" : [ 0, 0 ] }
])
db.Listings.ensureIndex({location:"2dsphere"})
assert.eq(3, db.Listings.find( { location : { $geoWithin : { $box : [[-5,-5], [5,5]] } } } ).sxplain().n)
assert.eq(3, db.Listings.find( { location : { $geoWithin : { $box : [[-5,-5], [5,5]] } } } ).sort({_id:1}).explain().n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment