标签:
db.places.insert( { loc : { type: "Point", coordinates: [ -73.97, 40.77 ] }, name: "Central Park", category : "Parks" } ) db.places.insert( { loc : { type: "Point", coordinates: [ -73.88, 40.78 ] }, name: "La Guardia Airport", category : "Airport" } )建立索引
db.places.ensureIndex( { loc : "2dsphere" } )參数不是1或-1,为2dsphere。
db.places.ensureIndex( { loc : "2dsphere" , category : -1, name: 1 } )
db.places.find( { loc : { $geoWithin : { $geometry : { type : "Polygon" , coordinates : [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ] ] } } } } )
db.places.find( { loc : { $near : { $geometry : { type : "Point" , coordinates : [ <longitude> , <latitude> ] } , $maxDistance : <distance in meters> } } } )
db.places.find( { loc : { $geoWithin : { $centerSphere : [ [ -88 , 30 ] , 10 ] } } } )
标签:
原文地址:http://www.cnblogs.com/yxwkf/p/3871022.html