【发布时间】:2018-06-04 02:39:35
【问题描述】:
我想根据其中的 sort_order 键更改幻灯片子文档中对象的顺序。
例如:我想将标题为 A3 的幻灯片移到 A2 上方。 IE。 sort_orderA3 (3)的值改为2,A2的值将改为3 ,如果向下移动,反之亦然。
怎么办??
下面是 db 对象。
{
"_id" : ObjectId("5a3b8cc68884dd1140a9a5b8"),
"title" : "Sort Test",
"user_id" : ObjectId("59e08e45f081170f582e95cc"),
"status" : "active",
"slides" : [
{
"_id" : ObjectId("5a3b8cc68884dd1140a9a5b9"),
"sort_order" : 0,
"content" : "Sort Test",
"title" : "Sort Test"
},
{
"_id" : ObjectId("5a3b8cda8884dd1140a9a5ba"),
"sort_order" : 1,
"content" : "Text Contents here...",
"title" : "A1"
},
{
"_id" : ObjectId("5a3b8ce48884dd1140a9a5bb"),
"sort_order" : 2,
"content" : "Text Contents here...",
"title" : "A2"
},
{
"_id" : ObjectId("5a3b8cec8884dd1140a9a5bc"),
"sort_order" : 3,
"content" : "Text Contents here...",
"title" : "A3"
},
{
"_id" : ObjectId("5a3b8cec8884dd1140455bc"),
"sort_order" : 4,
"content" : "Text Contents here...",
"title" : "A4"
}
],
"description" : "Sort Test",
"__v" : 0
}
【问题讨论】:
标签: javascript arrays node.js mongodb mongoose