0

在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" }

我怎样才能做到这一点??

4

1 回答 1

3

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

于 2013-05-14T10:41:37.973 回答