search

Home  >  Q&A  >  body text

nosql - MongoDB 官方文档中的 aggregate 例子当中的 $sum: 1 , 这里的 1 起什么作用?

db.restaurants.aggregate( 
[ 
{ $match: { "borough": "Queens", "cuisine": "Brazilian" } }, 
{ $group: { "_id": "$address.zipcode" , "count": { $sum: 1 } } } 
]
);
怪我咯怪我咯2758 days ago688

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-28 09:06:16

    http://docs.mongodb.org/manual/reference/operator/aggregation/sum/

    Sum by expression value 1 represents 1

    reply
    0
  • 世界只因有你

    世界只因有你2017-04-28 09:06:16

    According to the conditions of the group, if one condition is met, add 1, that is, count is the number of each zipcode in the group

    reply
    0
  • Cancelreply