mongodb中aggregate()有什么用

mongodb中aggregate()的作用:在mongodb中aggregate()主要是用来处理数据并返回计算后的数据结果,比如统计平均值,求和等运算操作,aggregate()的语法如:“db.COLLECTION_NAME.aggregate(AGGREGATE_OPERATION)”。
在这里插入图片描述
具体内容如下:

aggregate() 方法的基本语法格式如下所示

>db.COLLECTION_NAME.aggregate(AGGREGATE_OPERATION)

实例

集合中的数据如下:

{
   _id: ObjectId(7df78ad8902c)

   title: 'MongoDB Overview', 

   description: 'MongoDB is no sql database',

   by_user: 'runoob.com',

   url: 'http://www.runoob.com',

   tags: ['mongodb', 'database', 'NoSQL'],

   likes: 100

},

{

   _id: ObjectId(7df78ad8902d)

   title: 'NoSQL Overview', 

   description: 'No sql database is very fast',

   by_user: 'runoob.com',

   url: 'http://www.runoob.com',

   tags: [

猜你喜欢

转载自blog.csdn.net/qq_39162487/article/details/129858789