mongoDB,mongoose,没有数组就添加,如果有了数组,就向数组中添加新元素
Posted 江山一族
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
})
以上是关于mongoDB,mongoose,没有数组就添加,如果有了数组,就向数组中添加新元素的主要内容,如果未能解决你的问题,请参考以下文章