```
> db.location.ensureIndex({"w":"2d"})
{
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.location.insert({w:[1,1]})
WriteResult({ "nInserted" : 1 })
> db.location.insert({w:[1,2]})
WriteResult({ "nInserted" : 1 })
> db.location.insert({w:[3,2]})
WriteResult({ "nInserted" : 1 })
> db.location.insert({w:[100,100]})
WriteResult({ "nInserted" : 1 })
> db.location.insert({w:[200,100]})
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 13027,
"errmsg" : "point not in interval of [ -180, 180 ] :: caused by :: { _id: ObjectId('5870915a9a0bf268727ed5c0'), w: [ 200.0, 100.0 ] }"
}
})
> db.location.insert({w:[180,100]})
WriteResult({ "nInserted" : 1 })
> db.location.remove({w:[180,100]})
WriteResult({ "nRemoved" : 1 })
> db.location.insert({w:[180,80]})
WriteResult({ "nInserted" : 1 })
> db.location.find({w:{$near:[1,1]}})
{ "_id" : ObjectId("587091389a0bf268727ed5bc"), "w" : [ 1, 1 ] }
{ "_id" : ObjectId("5870913c9a0bf268727ed5bd"), "w" : [ 1, 2 ] }
{ "_id" : ObjectId("587091419a0bf268727ed5be"), "w" : [ 3, 2 ] }
{ "_id" : ObjectId("587091509a0bf268727ed5bf"), "w" : [ 100, 100 ] }
{ "_id" : ObjectId("587091979a0bf268727ed5c2"), "w" : [ 180, 80 ] }
> db.location.find({w:{$near:[1,1],$maxDistance:10}})
{ "_id" : ObjectId("587091389a0bf268727ed5bc"), "w" : [ 1, 1 ] }
{ "_id" : ObjectId("5870913c9a0bf268727ed5bd"), "w" : [ 1, 2 ] }
{ "_id" : ObjectId("587091419a0bf268727ed5be"), "w" : [ 3, 2 ] }
> db.location.find({w:{$near:[1,1],$maxDistance:10,$minDistance:1}})
{ "_id" : ObjectId("5870913c9a0bf268727ed5bd"), "w" : [ 1, 2 ] }
{ "_id" : ObjectId("587091419a0bf268727ed5be"), "w" : [ 3, 2 ] }
> db.location.find({w:{$near:[1,1],$maxDistance:10,$minDistance:2}})
{ "_id" : ObjectId("587091419a0bf268727ed5be"), "w" : [ 3, 2 ] }
> db.location.find({w:{$near:[1,1],$maxDistance:10,$minDistance:3}})
>
```
网友评论