[试图从集合中删除_id,但不起作用。我不知道如何解决此问题。任何人都需要帮助。
model.js:
const schemmaodel = new mongoose.Schema({
"name": { type: string}
}, { _id: false, versionKey: false });
data.controller.js:
var newModel = require(path.resolve('./models/model.js'))(collectionName);
newModel.create({}, function(err, doc) {
});
_id
就像集合的主键。如果在架构中未指定_id
,则默认情况下,猫鼬会选择_id
类型的ObjectId
。
根据猫鼬documentation,您只能在子文档上禁用_id
。因此,在您的情况下,schemmaodel
被视为父模式,并且由于在保存时已在父模式上设置了{ _id: false }
选项,将引发与缺少_id