0

我有猫鼬 Shcema:

Track = new Schema({ title: 'string', 艺术家: 'string' })

在我的数据库集合中,我有 object: { title: 'title1', artist: 'artist1', status: '1' }

状态不在模式中,但仍由 find 方法检索。我认为架构应该能够限制这一点。

是否可以通过 findOne 或 findById 等检索此对象,而无需自动排除状态属性而无需通过 {status: 0} 明确指出它?

4

1 回答 1

3

您可以通过将status字段添加到架构中来做到这一点,但将其选择默认设置为false

Track = new Schema({
    title: 'string', 
    artist: 'string', 
    status: { type: String, select: false }
});
于 2012-11-05T21:20:06.637 回答