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
})spa

相關文章
相關標籤/搜索