0

我在 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转换器

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

我错过了什么?

谢谢,

4

1 回答 1

1

似乎您错过了对 的电话sort,例如:

db.coll.find().sort({id_double: 1, address: 1, loctype: 1, locname: 1})
于 2013-06-19T12:17:25.863 回答