CNode

Mongoose 查询时怎么返回指定的列呢?

Ddolphinboy发布于14 年前最后回复14 年前1 回复12272 浏览0 收藏

查询时间段里面的数据:

Model.find({create_at: {$gte: bdate, $lte: edate}}, function(err, data){
    ……
}

想要返回指定的列,该怎么做呢?

查看回复

回复 (1)

D
dolphinboy#1·14 年前

傻了一下,哈哈,官网网站有例子:

var Person = db.model('Person', yourSchema);

// 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.
})

'name occupation' 就是指定要返回的字段

参与回复
登录后即可参与回复。登录