这是我的用户架构:
const userSchema = mongoose.Schema({
userid: String,
username: String,
pwd: String,
login_devices: {
type: Object,
default: {
currentDevice: "",
devicesList: [],
},
},
});
我的问题是:
感谢帮助
答案 0 :(得分:0)
获取所需的文档并像在 javascript 对象中一样添加元素。然后使用 mongoose .save()
函数更新对象。
const user = await this.UserModel.find({});
user.login_devices.default.devicesList.push(new device);
return await user.save()