阿里云mongodb 添加地理位置索引的心酸路。
前景提要:我们公司在aliyun 购买一台mongodb 服务,最近在项目中需要使用到地理位置排序功能。
1、登入阿里云DMS ,进入查询窗口,执行地理索引创建指令
db.home_store.ensureIndex( { loc : "2dsphere" } )
阿里云DMS 提示如下信息:
"Sorry this function is deprecated, and DMS do not support . Please use db.collection.createIndex()"
效果截图:
2、资讯阿里云售后服务,给出的解决答案:
根据阿里云 售后服务给出的答案,只能通过公网服务器,连接mongodb shell 创建地理位置索引。
3、我使用了一台公司在公网的服务器(CentOS6.5),下载mongodb 客户端,进行mongodb 的shell 连接,但是问题又接踵而至:
[root@iZ94qawymalZ bin]# ./mongo --host dds-wz9fc7e1efae1c**.mongodb.rds.aliyuncs.com:3717 -u *** -p **** --authenticationDatabase admin
MongoDB shell version: 2.4.9
connecting to: dds-wz9fc7e1efae1c841.mongodb.rds.aliyuncs.com:3717/test
Thu Nov 10 10:13:12.040 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:228
exception: login failed
根据上面的反馈信息,我们可以清楚的看出:连接mongodb 认证失败。
啊,悲催!!!!!!!
4、再次在阿里云工单服务中发起紧急工单,这次阿里的售后服务,等的我花开花落好久,不过最后,售后的帅哥靓妹们还是给出了相关解决答案:
给出这样的答案,我吐血了,我使用的是mongodb 2.4.9 版本客户端,心里油然升起(日*******************),没办法,只能将mongodb 的版本由2.4.9提升3.4.2.
5、给出我在公网服务器(centos)连接mongodb shell 的指令代码:
[root@iZ94qawymalZ local]# cd mongodb
[root@iZ94qawymalZ mongodb]# ls -a
. .. bin GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
[root@iZ94qawymalZ mongodb]# cd bin
[root@iZ94qawymalZ bin]# ./mongo --host dds-wz9fc7e1efae1c***.mongodb.rds.aliyuncs.com:3717 --authenticationDatabase admin -u ** -p ****
MongoDB shell version: 3.2.1
connecting to: dds-wz9fc7e1efae1c***.mongodb.rds.aliyuncs.com:3717/test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
mgset-2066113:PRIMARY> show dbs;
admin 0.000GB
local 0.088GB
wgbj_db 0.050GB
wlsq_db_main 0.011GB
mgset-2066113:PRIMARY> use wgbj_db
switched to db wgbj_db
mgset-2066113:PRIMARY> show collections;
homeDeviceLog
homeDeviceReport
homeGatewayMongodb
homeUserMsg
home_store
system.profile
waterFlowDay
waterFlowWeek
mgset-2066113:PRIMARY> db.home_store.ensureIndex( { loc : "2dsphere" } )
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
mgset-2066113:PRIMARY> use admin
switched to db admin
mgset-2066113:PRIMARY> db.home_store.ensureIndex( { loc : "2dsphere" } )
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
mgset-2066113:PRIMARY> shwo dbs
2016-11-10T11:25:02.068+0800 E QUERY [thread1] SyntaxError: missing ; before statement @(shell):1:5
mgset-2066113:PRIMARY> show dbs;
admin 0.000GB
local 0.088GB
wgbj_db 0.050GB
wlsq_db_main 0.011GB
mgset-2066113:PRIMARY> use wlsq_db_main
switched to db wlsq_db_main
mgset-2066113:PRIMARY> show collections
homeDeviceLog
homeGatewayMongodb
homeUserMsg
home_store
system.profile
mgset-2066113:PRIMARY> wlsq_db_main.home_store.ensureIndex({ loc:"2dsphere"})
2016-11-10T11:27:35.037+0800 E QUERY [thread1] ReferenceError: wlsq_db_main is not defined :
@(shell):1:1
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。