更改特定mongo记录的顺序

时间:2013-05-14 09:02:54

标签: mongodb mongoid

mongodb记录中的

就像这样

{ "_id" : ObjectId("5191fc1206610430cd000004"), "ancestry" : null, "name" : "root" }
{ "_id" : ObjectId("5191fc1306610430cd000005"), "ancestry" : null, "name" : "root1"}
{ "_id" : ObjectId("5191fc2706610430cd000006"), "ancestry" : null, "name" : "root2"}
{ "_id" : ObjectId("5191fc2806610430cd000007"), "ancestry" : null, "name" : "root3"}

我想改变这样的记录顺序

{ "_id" : ObjectId("5191fc2706610430cd000006"), "ancestry" : null, "name" : "root2"}
{ "_id" : ObjectId("5191fc1206610430cd000004"), "ancestry" : null, "name" : "root" }
{ "_id" : ObjectId("5191fc1306610430cd000005"), "ancestry" : null, "name" : "root1"}
{ "_id" : ObjectId("5191fc2806610430cd000007"), "ancestry" : null, "name" : "root3"}

我有以下信息 要移动的节点

{ "_id" : ObjectId("5191fc2706610430cd000006"), "ancestry" : null, "name" : "root2"}

在哪个节点之前移动

{ "_id" : ObjectId("5191fc1206610430cd000004"), "ancestry" : null, "name" : "root" }

我该怎么做?

1 个答案:

答案 0 :(得分:3)

你做不到。您无法更改记录的顺序。它们按objectId(几乎)排序。如果要根据参数进行排序,请将其放入对象并按该参数排序。