mongoDb以错误的顺序查找数据

时间:2013-06-19 11:59:26

标签: mongodb

我在mongoDB中有表,我想按照以下顺序获取数据:

我的集合包含多个元素:_id, address, locname, loctype, id_double,

我希望获得所有数组但具有不同的元素顺序,如:

id_double, address, loctype, locname

所以我写了查询:

db.coll.find({},{"_id":0, "id_double":1, "address":1, "loctype":1, "locname":1}) 

但订单错误:

{ "loctype" : "Hospital",  "locname" : "Alex", "address" : "Alrad",  "id_double" : 21 }
{ "address" : "Bukit",     "id_double" : 1,    "locname" : "KKH",    "loctype" :   "Clinic/Hospital" }
{ "address" : "Thirdenue", "id_double" : 2,    "locname" : "Singae", "loctype" :   "Clinic/Hospital" }
{ "address" : "Avenue",    "id_double" : 3,    "locname" : "Nation", "loctype" :   "Clinic/Hospital" }
{ "address" : "tal Drive", "id_double" : 4,    "locname" : "SGH",    "loctype" :   "Clinic/Hospital" }

[编辑]

我使用了mySql - > mongodb converter

似乎上面提到的语法有效并且必须以相同的顺序返回数据

我错过了什么吗?

谢谢,

1 个答案:

答案 0 :(得分:1)

似乎您错过了对sort的通话,例如像这样:

db.coll.find().sort({id_double: 1, address: 1, loctype: 1, locname: 1})