常见评论回复需求,但想按插入顺序查询,例如目前有两条评论回复数据:
[{
name: "小红",
content: "小红回复:xxxxx",
},{
name: "小蓝",
content: "小蓝回复:xxxxx",
}]
此时小明回复小红,我想插入在小红数据后面,例如取出的数据是这样的:
[{
name: "小红",
content: "小红回复:xxxxx",
},{
name: "小明",
content: "小明回复小红说:xxxx",
},{
name: "小蓝",
content: "小蓝回复:xxxxx",
}]
这种需求怎么实现呢?
MongoDB shell 命令:
然后:
`
db.comments.find().sort({sequence: 1});`