Mongoose: 如果多次使用子模式,则“ select:false”不能作为子模式的一部分

创建于 2017-08-31  ·  3评论  ·  资料来源: Automattic/mongoose

您是否要请求功能或报告错误
漏洞

目前的行为是什么?

在下面的脚本中,当我们提取父文档时,我们看到child返回为{} ,但是child2返回为{ field: 'test'}尽管事实上ChildSchema.field具有select: false

在查看调试器时,仅选择了child.field而没有选择child2.field



const mongoose = require('mongoose');

mongoose.connect('mongodb://127.0.0.1/test');
const db = mongoose.connection;

db.once('open', async () => {
  try {
    const ChildSchema = new mongoose.Schema({
      field: {
        type: String,
        select: false,
      },
      _id: false,
    }, { id: false });

    const ParentSchema = new mongoose.Schema({
      child: ChildSchema,
      child2: ChildSchema,
    });
    const Parent = mongoose.model('Parent', ParentSchema);
    const ogParent = new Parent();
    ogParent.child = { field: 'test' };
    ogParent.child2 = { field: 'test' };
    await ogParent.save();

    const foundParent = await Parent.findById(ogParent._id).exec();
    console.log(foundParent);

    db.close();
  } catch (e) {
    console.log(e);
  }
});


请提及您的node.js,mongoose和MongoDB版本。
4.11.8

confirmed-bug

最有用的评论

@wlingke ,发现了自2014年以来猫鼬中所有最细微的错误:rocket :: 1st_place_medal:

image

所有3条评论

感谢完整的repro脚本,这看起来像个bug

@wlingke颁发假想徽章,以纪念2017年年度最佳猫鼬错误查找器🐜

@wlingke ,发现了自2014年以来猫鼬中所有最细微的错误:rocket :: 1st_place_medal:

image

此页面是否有帮助?
0 / 5 - 0 等级