mongoDB,mongoose,没有数组就添加,如果有了数组,就向数组中添加新元素

db.getCollection('photos').findOneAndUpdate("5b028e71f32bd5004f905879",   //findByIdAndUpdate
{
'$push':{ 'orderHistory':{
"userId":"5b10d49320b805a7844ae5ec",
"customerId":"888888888888",
"createdOn":ISODate("2018-06-01T21:29:57.141+08:00")
}
}
},{
'upsert': true
})

猜你喜欢

转载自www.cnblogs.com/qiyc/p/9132251.html