2015-10-04 38 views
2

我想排除Mongoose設置的虛擬ID字段。Mongoose:如何在填充期間排除虛擬ID字段

var Bar = new Schema({ body: String });  
var Foo = new Schema({ bars: type: Schema.Types.ObjectId, ref: 'Bar' }); 

Foo 
.find({..query...}) 
.populate('bars', 'body -_id') 
.exec(function(err, foos){ 
    console.log(foos); // { bars: [{id: null, body: 'body string'}] } 
}); 

如何擺脫'id'字段?無論如何,因爲我已經排除了_id填充?

+0

不''身體-_id -id''工作? – royhowie

+1

不是,它刪除_id,但留下ID分配爲空。 – elloworld111

回答

0

您可以禁用模式選項中的虛擬id字段(see documentation here)。在你的情況下,它應該是這樣的:

var Bar = new Schema({ body: String }, { id: false }); 
相關問題