2016-03-15 19 views
0

我收集的MongoDB這樣的:角fullstack:調用API沒有_id,像findByField

var CategorySchema = new mongoose.Schema({ 
Name: String, 
Description: String, 
Picture: { 
    type: String, 
    default: 'http://placehold.it/64x64'}, 
Level: { 
    type: Number, 
    default: 1}, 
Owner:{ 
    type: Schema.ObjectId, 
    ref: 'Category'} 
}); 

怎樣才能得到業主使用,因爲這個API只是可以得到由_id導致。

回答

0

你可以這樣說:

var owner = {ref:'Category}; 
    category_model.findOne({owner: owner}, 'ref', {lean: true}, function (err, owner) { 
    }); 
+0

謝謝你,我會嘗試。但什麼是'category_model' –

+0

這是一個貓鼬模型,請參閱http://mongoosejs.com/docs/2.7.x/docs/model-definition.html – alexey