mongodb使用mongoose分组查询
一个分组查询的例子:
model.aggregate([{$match: ops}, {$unwind: '$details'}, {$sort: {create_at: -1}}, {
$group: {
_id: {
promotion_id: "$promotion_id",
product_id: '$details.product_id',
need_pay: '$need_pay'
},
product_name: {$first:"$details.name"},
price: {$max: "$details.price"},
amount: {$sum: "$details.amount"},
packing: {$sum: "$details.packing"},
quantity: {$sum: "$details.quantity"}
}
}, {$match: ops2}, {
$group: {
_id: {
promotion_id: "$_id.promotion_id",
need_pay: '$_id.need_pay'
},
details: {
$push: {
product_id: "$_id.product_id",
name: '$product_name',
price: '$price',
amount: '$amount',
packing: '$packing',
quantity: '$quantity'
}
}
}
}], fn);
mongodb使用mongoose分组查询的更多相关文章
- Mongodb for C# 分组查询
#region 排序获取集合 static List<BsonDocument> GetPagerWithGroup(string connectionString, string dat ...
- mongodb 分组查询
数据的保存 include_once 'mDB.class.php'; $m=new mDB(); $m->setDB('mydb'); // $m->save('stu',['dept' ...
- MongoDB之 分组查询
分组查询 可视化工具 https://robomongo.org pymongo from pymongo import MongoClient # 方式一: c = MongoClient(host ...
- NodeJs操作MongoDB之多表查询($lookup)与常见问题
NodeJs操作MongoDB之多表查询($lookup)与常见问题 一,方法介绍 aggregate()方法来对数据进行聚合操作.aggregate()方法的语法如下 1 aggregate(ope ...
- 浅析mongodb中group分组
这篇文章主要介绍了浅析mongodb中group分组的实现方法及示例,非常的简单实用,有需要的小伙伴可以参考下. group做的聚合有些复杂.先选定分组所依据的键,此后MongoDB就会将集合依据选定 ...
- Practical Node.js (2018版) 第5章:数据库 使用MongoDB和Mongoose,或者node.js的native驱动。
Persistence with MongoDB and Mongoose https://github.com/azat-co/practicalnode/blob/master/chapter5/ ...
- BBS--功能4:个人站点页面设计(ORM跨表与分组查询)
查询: 日期归档查询 1 date_format ============date,time,datetime=========== create table t_mul_new(d date,t t ...
- 5 功能4:个人站点页面设计(ORM跨表与分组查询)
1.个人站点页面文章的查询 # 个人站点 http://www.cnblogs.com/wh1520577322/ http://www.cnblogs.com/liucong12345/ http: ...
- MongoDB 和 Mongoose 04
一.安装 1. 相关 https://www.mongodb.org/dl/win32/ MongoDB的版本偶数版本为稳定版,奇数版本为开发版 MongoDB对于32位系统支持不佳,所以3.2版本以 ...
随机推荐
- 在 MacOS 上编译链接 OpenGL 程序
几个星期以前开始折腾在我的MBA上写 OpenGL 小程序.我不太熟悉MacOS上的开发工具比如XCode,所以一开始的想法就是用vim来写程序,然后手工编译链接.网上查了一下,MacOS上的Open ...
- 多线程与网络之SDWebImage和NSCache
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- js自定义排序
摘要 有个js对象数组 var ary=[{id:1,name:"b"},{id:2,name:"b"}] 需求是根据name 或者 id的值来排序,这里有个风 ...
- 初识SQL注入
什么是SQL注入(SQL Injection)? SQL注入是网站攻击途径之一,这里引用一下百度百科的解释:“所谓SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串, ...
- HW6.28
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- 全栈式框架的选择:MEAN or MEANS?
说明:个人博客地址为edwardesire.com,欢迎前来品尝.本博客作为备份和引流 这两个月一直在进行sails后端开发,其中遇到的问题不断.放在研究用户访问控制矸例程上的时间太多,最后也没用弄出 ...
- java 通过网络 ntp 获取网络时间
需要 commons-net-3.4.jar 库. import org.apache.commons.net.ntp.NTPUDPClient; import org.apache.commons. ...
- Finite Difference Method with Mathematica
Euler's method
- sqlite3使用教程1 SQLite 命令
http://www.runoob.com/sqlite/sqlite-commands.html 本章将向您讲解 SQLite 编程人员所使用的简单却有用的命令.这些命令被称为 SQLite 的点命 ...
- HDU4632:Palindrome subsequence(区间DP)
Problem Description In mathematics, a subsequence is a sequence that can be derived from another seq ...