MongoDB 正在更新对象内部的布尔值
MongoDB Updating Boolean Inside Object
我正在尝试更新我的 discord.js v13 bot 中对象内部的布尔值,但它没有更新这里是我尝试过的事情:
await guildSchema.findOneAndUpdate({
logging.enabled: true
})
await guildSchema.findOneAndUpdate({
logging.enabled = true
})
但是none这些好像要更新了这里是db
的截图
我也试过:
await guildSchema.findOneAndUpdate({
logging: {"enabled": true}
})
这会更新它,但也会删除其他所有内容
Your error is passing the update statement to the filter parameter.
Your query will find the first doc with { 'logging.enabled' : true }.
And don't update anything
const filter = { 'logging.enabled' : false};
const update = { 'logging.enabled' : true };
// `doc` is the document _before_ `update` was applied
let doc = await guildSchema.findOneAndUpdate(filter, update);
// doc.logging.enabled is false
// `doc` is the document _after_ `update` was applied because of
// `new: true`
let doc = await guildSchema.findOneAndUpdate(filter, update, {
new: true
});
// doc.logging.enabled is true
我正在尝试更新我的 discord.js v13 bot 中对象内部的布尔值,但它没有更新这里是我尝试过的事情:
await guildSchema.findOneAndUpdate({
logging.enabled: true
})
await guildSchema.findOneAndUpdate({
logging.enabled = true
})
但是none这些好像要更新了这里是db
的截图我也试过:
await guildSchema.findOneAndUpdate({
logging: {"enabled": true}
})
这会更新它,但也会删除其他所有内容
Your error is passing the update statement to the filter parameter.
Your query will find the first doc with { 'logging.enabled' : true }.
And don't update anything
const filter = { 'logging.enabled' : false};
const update = { 'logging.enabled' : true };
// `doc` is the document _before_ `update` was applied
let doc = await guildSchema.findOneAndUpdate(filter, update);
// doc.logging.enabled is false
// `doc` is the document _after_ `update` was applied because of
// `new: true`
let doc = await guildSchema.findOneAndUpdate(filter, update, {
new: true
});
// doc.logging.enabled is true