.save 不是函数,.map 不是更新文档时的函数
.save is not a function and .map is not a function while updating document
我有以下代码:当我尝试从邮递员那里发送时,它说:
"message": "account.save is not a function"
const account = await Account.find({ "buildings.gateways.devices.verificationCode": code })
var accountId = account ? account.map(item => item._id) : null
const buildings = _.flatMap(account, a => a.buildings)
const gateways = _.flatMap(buildings, b => b.gateways);
const devices = _.flatMap(gateways, g => g.devices);
// finding deviceId to insert for user from that account
const device = _.filter(devices, d => d.verificationCode === code);
device.patientFirstName = req.body.firstName;
device.patientLastName = req.body.lastName;
account.save();
如果我尝试更改为 findOne(),那么它会显示
"account.map is not a function"
帐户总是 returns 值那么为什么它不能映射我不明白。
感谢您的帮助。谢谢
.find()
returns 一个数组,这样你就可以 运行 Array.map()
但你需要 .save()
每个文件分开:
const accounts = await Account.find({ "buildings.gateways.devices.verificationCode": code })
var accountId = account ? account.map(item => item._id) : null
for(let account of accounts){
await account.save();
}
.findOne()
(等待)returns 单个文档,因此您不能使用 .map()
:
const account = await Account.findOne({ "buildings.gateways.devices.verificationCode": code })
var accountId = account ? account._id : null
account.save();
我有以下代码:当我尝试从邮递员那里发送时,它说:
"message": "account.save is not a function"
const account = await Account.find({ "buildings.gateways.devices.verificationCode": code })
var accountId = account ? account.map(item => item._id) : null
const buildings = _.flatMap(account, a => a.buildings)
const gateways = _.flatMap(buildings, b => b.gateways);
const devices = _.flatMap(gateways, g => g.devices);
// finding deviceId to insert for user from that account
const device = _.filter(devices, d => d.verificationCode === code);
device.patientFirstName = req.body.firstName;
device.patientLastName = req.body.lastName;
account.save();
如果我尝试更改为 findOne(),那么它会显示
"account.map is not a function"
帐户总是 returns 值那么为什么它不能映射我不明白。
感谢您的帮助。谢谢
.find()
returns 一个数组,这样你就可以 运行 Array.map()
但你需要 .save()
每个文件分开:
const accounts = await Account.find({ "buildings.gateways.devices.verificationCode": code })
var accountId = account ? account.map(item => item._id) : null
for(let account of accounts){
await account.save();
}
.findOne()
(等待)returns 单个文档,因此您不能使用 .map()
:
const account = await Account.findOne({ "buildings.gateways.devices.verificationCode": code })
var accountId = account ? account._id : null
account.save();