定义
行为
示例
请考虑包含以下文档的 conferencePlanning 集合:
db.conferencePlanning.insertMany( [ { "_id" : 1, "city" : "New York", "hours" : 80, "tasks" : 7 }, { "_id" : 2, "city" : "Singapore", "hours" : 40, "tasks" : 4 } ] )
The following aggregation uses the $divide expression to divide the hours field by a literal 8 to compute the number of work days:
db.planning.aggregate( [ { $project: { city: 1, workdays: { $divide: [ "$hours", 8 ] } } } ] )
操作返回以下结果:
{ "_id" : 1, "city" : "New York", "workdays" : 10 } { "_id" : 2, "city" : "Singapore", "workdays" : 5 }