我收到错误TypeError:当我想在我的mongoDB集合用户字段中的financial.deposit内部推送值时,无法设置未定义的属性'financial.deposits';
const query = {};
query["$push"]["financial.deposits"] = {
hello: "hello"
}
await UserModel.update({ _id: key }, query).exec();
我尝试了这个,但是它抛出了异常。
答案 0 :(得分:0)
您的查询应如下所示:
const query = {$push:{"financial.deposite":{['key1']:"anything"}}};
db.usertest.update({ "_id" : ObjectId("5d4976ac1f28f608707dba3c")}, query)