mongoose,find,返回特定的属性

我有这个电话:

exports.getBIMFromProject = function(req, res){ mongoose.model('bim').find({projectId: req.params['prj_id']}, function(err, bim){ if(err){ console.error(err); res.send(500) } res.send(200, bim); }); }; 

我在哪里指定我想返回哪些属性? 在文档中找不到它。 以上返回整个对象。 我只想要返回一些属性。

这是我的模式:

 var mongoose = require('mongoose'), Schema = mongoose.Schema; var bimSchema = new Schema({ projectId: Number, user: String, items:[ { bimObjectId: Number, typeId: String, position:{ floor: String, room:{ name: String, number: String } } } ] }); mongoose.model('bim', bimSchema); 

我不想要包含在我的rest电话中的项目数组。

你使用投影。 mongoose查询文档中的第一个例子有一个投影操作。

注意:不是真正的代码B / C我突出了与三星重要的位

 // find each person with a last name matching 'Ghost', ***selecting the `name` and `occupation` fields*** Person.findOne({ 'name.last': 'Ghost' }, ***'name occupation'***, function (err, person) { if (err) return handleError(err); console.log('%s %s is a %s.', person.name.first, person.name.last, person.occupation) // Space Ghost is a talk show host. }) 

Person架构没有指定,但我认为这个例子已经足够清楚了。

您需要定义您的模型模式http://mongoosejs.com/docs/guide.html