aggregate

Need to group records based on matching reversal in sql

谁说胖子不能爱 提交于 2020-03-28 07:02:11
问题 I have a tricky scenario to aggregate the data. Data in my source table is as follows. CustomerId Transaction Type Transaction Amount 1 Payment 100 1 ReversePayment -100 1 payment 100 1 ReversePayment -100 1 Payment 100 1 Payment 100 Requirement is as follows: If the payment as a assoociated Reversepayment with matched amount, sum these two records. If the payment does not have an associated Reverse payment, consider it as orphan(dont sum it). I want output to be like this. CustomerId

Add a value to to the record using aggregation

我与影子孤独终老i 提交于 2020-03-28 06:39:17
问题 sample of my document { _id: "bmasndvhjbcw", name: "lucas", occupation: "scientist", present_working:true, age: 55, location: "texas", }, { _id: "bmasndvhjbcx", name: "mark", occupation: "scientist", age: 45, present_working:true, location: "texas", }, { _id: "bmasndvhjbca", name: "stuart", occupation: "lab assistant", age: 25, location: "texas", }, { _id: "bmasndvhjbcq", name: "cooper", occupation: "physicist", age: 69, location: "texas" } ] For the records which doesn't have present_working

How entities covered with in an aggregate Root are saved in DDD?

别说谁变了你拦得住时间么 提交于 2020-03-25 18:54:13
问题 After reading lot of posts, I realised if an aggregate root exists for a concept/context, we need to have a single repository for that whole concept/context. If thats the case, I see there won't be any repositories for the internal entities. If so, how these internal entities are saved to database? I have a many internal entities under the aggregate root. So, wondering If I need to have all the saving of the internal entities under the aggregate root repository, it's going to be bloated.

Mongoose 两个表关联查询aggregate 以及 Mongoose中获取ObjectId

半世苍凉 提交于 2020-03-24 11:50:23
Mongoose 两个表关联查询aggregate 通常两个表关联查询的时候,是一种一对多的关系,比如订单与订单详情就是一对多的关系,一个订单下面有多个商品 数据模拟 首先我们先将数据模拟出来,先选择数据库 use eggcms db.order.insert({"order_id":"1","uid":10,"trade_no":"111","all_price":100,"all_num":2}) db.order.insert({"order_id":"2","uid":7,"trade_no":"222","all_price":90,"all_num":2}) db.order.insert({"order_id":"3","uid":9,"trade_no":"333","all_price":20,"all_num":6}) db.order_item.insert({"order_id":"1","title":"商品鼠标 1","price":50,num:1}) db.order_item.insert({"order_id":"1","title":"商品键盘 2","price":50,num:1}) db.order_item.insert({"order_id":"1","title":"商品键盘 3","price":0,num:1}) db

MongoDB学习day06--高级查询aggregate聚合管道和nodejs操作aggregate

风格不统一 提交于 2020-03-21 10:32:20
一、MongoDB聚合管道(Aggregation Pilpeline) 使用聚合管道可以对集合中的文档进行变换和组合。 主要功能:表的关联查询、数据统计 二、aggregate 管道操作符与表达式 管道操作符: sql 和 nosql 对比: 管道表达式: 管道操作符作为 “ 键 ”, 所对应的 “ 值 ” 叫做管道表达式。 例如 {$match:{status:"A"}} , $match 称为管道操作符, 而 status:"A" 称为管道表达式, 是管道操作符的操作数 (Operand) 。 三、数据模拟: db.order.insert({"order_id":"1","uid":10,"trade_no":"111","all_price":100,"all_num":2}) db.order.insert({"order_id":"2","uid":7,"trade_no":"222","all_price":90,"all_num":2}) db.order.insert({"order_id":"3","uid":9,"trade_no":"333","all_price":20,"all_num":6}) db.order_item.insert({"order_id":"1","title":"商品鼠标 1","price":50,num:1}) db

迭代器模式

末鹿安然 提交于 2020-03-17 08:09:10
某厂面试归来,发现自己落伍了!>>> 又称为游标模式, 它提供一种顺序集合、容器对象元素的方法, 而又无须暴露集合内部表示。 特征: 抽离集合对象迭代行为到迭代器中, 提供一致访问接口 属于行为型模式 适用场景: 1、访问一个集合对象的内容而无须暴露它的内部表示 2、为遍历不同的集合结构提供一个统一的访问接口 public interface Iterator< E > { /** * 获取下一个 * @return */ E next () ; /** * 是否存在下一个 * @return */ boolean hasNext () ; } public interface IAggregate< E > { /** * 添加 * @param element * @return */ boolean add ( E element) ; /** * 移除 * @param element * @return */ boolean remove ( E element) ; /** * 迭代器 * @return */ Iterator< E > iterator () ; } public class ConcreteIterator< E > implements Iterator< E > { private List< E > list ; private int

mongodb 高级操作

感情迁移 提交于 2020-03-16 06:26:35
聚合 aggregate 聚合(aggregate)主要用于计算数据,类似sql中的sum()、avg() 语法 db.集合名称.aggregate([{管道:{表达式}}]) 管道 管道在Unix和Linux中一般用于将当前命令的输出结果作为下一个命令的输入 ps ajx | grep mongo 在mongodb中,管道具有同样的作用,文档处理完毕后,通过管道进行下一次处理 常用管道 $group:将集合中的文档分组,可用于统计结果 $match:过滤数据,只输出符合条件的文档 $project:修改输入文档的结构,如重命名、增加、删除字段、创建计算结果 $sort:将输入文档排序后输出 $limit:限制聚合管道返回的文档数 $skip:跳过指定数量的文档,并返回余下的文档 $unwind:将数组类型的字段进行拆分 表达式 处理输入文档并输出 语法 表达式:'$列名' 常用表达式 $sum:计算总和,$sum:1同count表示计数 $avg:计算平均值 $min:获取最小值 $max:获取最大值 $push:在结果文档中插入值到一个数组中 $first:根据资源文档的排序获取第一个文档数据 $last:根据资源文档的排序获取最后一个文档数据 $group 将集合中的文档分组,可用于统计结果 _id表示分组的依据,使用某个字段的格式为'$字段' 例1:统计男生、女生的总人数

记录一次 MongoDB aggregate的性能优化经历

陌路散爱 提交于 2020-03-04 22:00:38
在一台配置为2核4G的阿里云服务器上,硬盘是普通的云盘(即SATA盘),除mongoDB外,运行了若干个java应用,单节点mysql和redis,mongo的实际可用内存在1.5G左右。单表数据200万条的时候,一个聚合函数响应时间约为6秒,页面端每秒请求一次,由于响应不够及时,页面刷新不及时,服务端堆积了大量的mongo aggregate请求,系统可用内存不足,直接导致了溢出,mongo服务被动shutdown。 mongod(ZN5mongo15printStackTraceERSo+0x41) [0x55bd3a2dd321] mongod(ZN5mongo29reportOutOfMemoryErrorAndExitEv+0x84) [0x55bd3a2dc954] mongod(ZN5mongo12mongoReallocEPvm+0x21) [0x55bd3a2d22b1] mongod(ZN5mongo11BufBuilderINS21SharedBufferAllocatorEE15growreallocateEi+0x83) [0x55bd38981833] mongod(ZN5mongo3rpc17OpMsgReplyBuilder22getInPlaceReplyBuilderEm+0x80) [0x55bd39d4b740] mongod(

need to group records based on matching reversals

南楼画角 提交于 2020-03-04 18:44:00
问题 This question is continuation to my earlier post. Need to group records based on matching reversal in sql I will be more clear with one complex example from my transaction table. Row_Number LOAN_ID TXN_ENTRY_API_NAME TXN_AMT 1 100 ReverseSpreadPayment 2250 2 100 SpreadPayment -2250 3 100 ReverseSpreadPayment 2250 4 100 SpreadPayment -2250 5 100 ReverseSpreadPayment 2250 6 100 SpreadPayment -2250 7 100 ReverseSpreadPayment 2250 8 100 ReverseSpreadPayment 2250 9 100 SpreadPayment 1000 In the

Axon参考指南 - 3.命令处理 - Aggregate(聚合)

岁酱吖の 提交于 2020-03-02 17:21:59
简述 在本章中,我们将更详细地介绍Axon应用程序中处理和调度命令的过程。这里将涉及诸如聚合建模,外部命令处理程序,命令分派和测试之类的主题。 1. Aggregate 基本使用 聚合是一个常规对象,其中包含状态和更改该状态的方法。创建Aggregate对象时,您实际上是在创建“ Aggregate Root”,通常带有整个Aggregate的名称。出于此描述的目的,将使用“礼品卡”域,这使我们将GiftCard作为汇总(根)。默认情况下,Axon将您的聚合配置为“基于事件的”聚合(如此处所述)。此后,我们的基本GiftCard聚合结构将重点关注事件采购方法: import org . axonframework . commandhandling . CommandHandler ; import org . axonframework . eventsourcing . EventSourcingHandler ; import org . axonframework . modelling . command . AggregateIdentifier ; import static org . axonframework . modelling . command . AggregateLifecycle . apply ; public class GiftCard {