我尝试使用
查询集合function activeNow(){
//some logic
//return a number between -1 and 7
}
conn.menu.aggregate([
{
$project: {
descrizione: 1,
validity: () => activeNow(this) //refer to current menu
}
},
{
$sort: {
validity: 1
}
}
]).exec().then(menu => {
// menu ordered by activeNow result
})
实际上它只返回字段_id和describezione,如:
[ { _id: 59898b6a41e78f02e4206034, descrizione: [ [Object] ] },
{ _id: 598c312bc0035d313c26c68b, descrizione: [ [Object] ] } ]
将Node与Mongoose和MongoDB 3.2.8一起使用