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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM