正确的方法来预先使用Mongoose数组?
我喜欢在数组中添加一个数组。 为了追加,我这样写。
Foo.update({ _id: id }, { $push: { bars: { $each: bars } } }, {upsert:true}, function(err){ });
有没有适当的方法来预先安排?
是的,你可以使用position: 0
db.Foo.update( { _id: id }, { $push: { bars: { $each: bars, $position: 0 } } } )