【发布时间】:2021-03-10 23:36:33
【问题描述】:
这是我当前的代码:
const mongoose = require("mongoose");
const schema = require("../schemas/ecos");
module.exports = async(req, res) => {
const db = await schema.findOne({
RobloxID: req.query.roblox_id
});
if(db.IsPendingVerification === "true") {
res.send({
success: true
})
db.updateOne({
IsNowVerified: "true"
})
}
}
目前它不会更新数据库,所以 IsNowVerified 是真的。为什么会这样?我没有收到任何错误。
我的生态档案:
const mongoose = require("mongoose");
const productSchema = mongoose.Schema({
Guild: { type: String, default: "" },
VerifyChannelID: { type: String, default: "" },
VerifyRoleID: { type: String, default: "" },
Prefix: { type: String, default: "v-" },
GuildToken: { type: String, default: "" },
HasGeneratedToken: { type: Number, default: 0 },
VerificationLevel1: { type: Boolean, default: false },
VerificationLevel2: { type: Boolean, default: false },
VerificationLevel3: { type: Boolean, default: false },
VerifcationRBLX: { type: Boolean, default: false },
VerificationRBLXGameLink: { type: Boolean, default: false },
VerifyMessageWelcomeID: { type: String, default: "" },
GuildName: { type: String, default: "" },
GuildInvite: { type: String, default: "" },
UserID: { type: String, default: "" },
RobloxID: { type: String, default: "" },
IsPendingVerification: { type: String, default: "" },
IsNowVerified: { type: String, default: "" }
});
module.exports = mongoose.model("Eco", productSchema, "ecos");
也就是mongodb数据库ecos的模块导出。
【问题讨论】:
-
你需要为
updateOne方法提供两个参数,filter和update命令。 mongoosejs.com/docs/api.html#query_Query-updateOne -
那么我的第二个参数是什么?
-
你能显示你的
schemas/ecos文件的内容吗? -
好的,现在可以了!
-
完成了,现在可以概览一下了