mongodb Mongoose findOne in an object在一个对象中找到一个

xoshrz7s  于 2023-11-17  发布在  Go
关注(0)|答案(1)|浏览(120)
const mongoose = require("mongoose");

const schema = new mongoose.Schema({
  integrations: {
    discord: {
      guild: {
        type: String,
        maxlength: [20, "Guild ID cannot be longer than 20 characters"],
        required: true,
      },
    },
  },
});

module.exports = mongoose.model("Hub", schema);

字符串
这是我的 Mongoose 模式。当使用.findOne时,我如何在integrations.discord.guild中通过其guild获得Hub

deyfvvtc

deyfvvtc1#

用于查询嵌套字段

Hub.findOne({'integrations.discord.guild': '----'})

字符串

相关问题