0
点赞
收藏
分享

微信扫一扫

educoderMongoDB 之滴滴、摩拜都在用的索引

一世独秀 2022-04-19 阅读 74

第1关:了解并创建一个简单索引

第2关:常见索引的创建

第3关:有趣的地理位置索引

echo "
db.people.insert({_id:1,name:'A',personloc:{type:'Point',coordinates:[116.403981,39.914935]}} );
db.people.insert({_id: 2,name: 'B',personloc: { type: 'Point', coordinates: [116.433733, 39.909511] }});
db.people.insert({_id: 3,name: 'C',personloc: { type: 'Point', coordinates: [116.488781, 39.949901] }});
db.people.insert({_id: 4,name: 'D',personloc: { type: 'Point', coordinates: [116.342609, 39.948021] }});
db.people.insert({_id: 5,name: 'E',personloc: { type: 'Point', coordinates: [116.328236, 39.901098] }});
db.people.insert({_id: 6,name: 'F',personloc: { type: 'Point', coordinates: [116.385728, 39.871645] }});
db.people.createIndex({ personloc: '2dsphere' });
db.runCommand({geoNear: 'people',near: { type: 'Point', coordinates: [116.403981, 39.914935] },spherical: true,minDistance: 100,maxDistance: 3000});
db.runCommand({geoNear: 'people',near: { type: 'Point', coordinates: [116.433733, 39.909511] },spherical: true,minDistance: 100,maxDistance: 5000});
db.runCommand({geoNear: 'people',near: { type: 'Point', coordinates: [116.488781, 39.949901] },spherical: true,minDistance: 3000,maxDistance: 8000});
db.runCommand({geoNear: 'people',near: { type: 'Point', coordinates: [116.342609, 39.948021] },spherical: true,minDistance: 3000,maxDistance: 8000});
"
#**********End**********#

 

举报

相关推荐

0 条评论