db.location.insert([ {"name":"广州","location":{"type":"Point","coordinates":[113.23,23.44]}}, {"name":"上海","location":{"type":"Point","coordinates":[121.23,31.24]}}, {"name":"北京","location":{"type":"Point","coordinates":[116,39]}}, {"name":"深圳","location":{"type":"Point","coordinates":[114,22]}}, {"name":"杭州","location":{"type":"Point","coordinates":[120.1,30.32]}}, {"name":"成都","location":{"type":"Point","coordinates":[104.23,30.44]}}, {"name":"武汉","location":{"type":"Point","coordinates":[114.23,30.44]}} ]);
2dsphere
db.location.createIndex({"location":"2dsphere"});
指定位置最近的点
db.location.findOne({"location":{$nearSphere:{$geometry:{type:"Point",coordinates:[113,23]}}}});