我喜欢在数组前面添加一个数组。 作为补充,我这样写。
Foo.update({ _id: id }, { $push: { bars: { $each: bars } } }, {upsert:true}, function(err){
});
是否有正确的前置方法?
最佳答案
是的,可以,使用位置:0
db.Foo.update(
{ _id: id },
{
$push: {
bars: {
$each: bars,
$position: 0
}
}
}
)
查看文档:https://docs.mongodb.org/manual/reference/operator/update/position/
关于node.js - 使用 Mongoose 前置数组的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36017402/