MongoDB中聚合主要用于处理数据,如统计平均值,求和等等,并返回计算后的数据结果。 1.?countcount函数返回指定集合中的数量。 db. mediaCollection.count()4 db. mediaCollection.find( { Publisher : "Apress", Type: "Book" } ).count()1 2. distinctdist
MongoDB中聚合主要用于处理数据,如统计平均值,求和等等,并返回计算后的数据结果。 1.?count count函数返回指定集合中的数量。> db. mediaCollection.count() 4 > db. mediaCollection.find( { Publisher : "Apress", Type: "Book" } ).count() 1
> db. mediaCollection.distinct( "Title") [ "Definitive Guide to MongoDB, the", "Nevermind" ] > db. mediaCollection.distinct ("Tracklist.Title") [ "In Bloom", "Smells like teen spirit" ]
> db. mediaCollection.group ( ... { ... key: {Title : true}, ... initial: {Total : 0}, ... reduce : function (items,prev) ... { ... prev.Total += 1 ... } ... } ... ) [ { "Title" : "Definitive Guide to MongoDB, the", "Total" : 1 }, { "Title" : "Nevermind", "Total" : 2 }, { "Title" : null, "Total" : 1 } ]
原文地址:mongodb 聚合命令, 感谢原作者分享。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号