jjzjj

aggregation

全部标签

java - Spring Data MongoDB 聚合 $out 管道

我正在使用SpringdatamongoDB并使用聚合来获取文档。ListoperationsList=newArrayList();operationsList.add(Aggregation.unwind("calendarEvent"));operationsList.add(Aggregation.match(criteria));operationsList.add(getMacroEventProjectionFields());if(start0){operationsList.add(Aggregation.limit(limit));}Aggregationaggre

java - 蒙戈 : How to count aggregation groups via Java's MongoTemplate

我有以下数据:{groupId:1,name:Jon},{groupId:1,name:Dan},{groupId:2,name:Jon},{groupId:2,name:Ris},{groupId:3,name:David}我收到一个groupID数组作为输入,我想计算这些组的DISTICT名称总数,我将聚合代码定义如下:groupIds[]={1,2}Aggregationagg=newAggregation(match(Criteria.where("groupId").in((groupIds)),group("name").count().as("total"));但我得到一

node.js - MongoDb $addFields 和 $match

在我的mongodb查询中,我使用$addFields添加ID字段,该字段连接了其他三个字段。我的问题是,如果我将新添加的字段与我要查询的值匹配,我将得不到任何结果。对于其他领域,它们工作得很好。orderofaggregationwhatisinaggregationdata=awaitmodel.aggregate([{$project:{projectName:1,price:1,'document':'$$ROOT'}},{$addFields:{'document.id':{$concat:['$document.propertyId.prefix','$document.p

javascript - 创建一个依赖于当前时间的 mongo View

我有一个包含日期字段的集合,我想创建一个按当前日期过滤所有文档的mongoView。例如,我希望我的View包含最近7天的所有文档。我有一个使用聚合管道创建View的javascript脚本。我使用javascript方法-newDate()来写入最近7天的情况:{"$lt":[{"$subtract":[newDate(),"$DateOfDocument"]},//differenceinmilliseconds1000*60*60*24*7//7daysinmilliseconds]}但是当我执行创建View的脚本时,mongo计算“newDate()”然后创建View,结果“n

mongodb - Mongoose aggregate Lookup - 如何按特定 id 过滤

我正在尝试制作一个聚合管道-$lookup以从另一个接收仅收集不等于特定_id的项目例如:诊所集合:{_id:1,name:'somename1'}{_id:2,name:'somename2'}{_id:3,name:'somename3'}业务集合:{_id:1,name:"somebusinessname",clinics:[1,2,3]}我的聚合管道查询:db.business.aggregate([{$match:{_id:mongoose.Types.ObjectId(businessId)}},{$lookup:{from:"ClinicsCollection",loca

mongodb - 具有多个字段的 Spring Data MongoDB 推送操作不起作用

我在MongoDB中有一组数据对象-[{"status":"passed","version":"124","value":6},{"status":"passed","version":"123","value":10},{"status":"failed","version":"123","value":16}]我想以这样的格式获取它-[{version:124,"series":[{"name":"passed","value":6}]},{version:123,"series":[{"name":"passed","value":10},{"name":"failed","v

mongodb aggregation : if value of two fields match, 将相应字典的另一个字段的值添加到新字段

在三个集合中使用聚合查找后,我得到以下结果。[{_id:"henten",location:"someplace",devices:[{"d_id":'d0001',"z_id":'z2001'},{"d_id":'d0002',"z_id":'z2002'}],store:[{"z_name":'vera',"z_id":'z2001'},{"z_name":'ghora',"z_id":'z2002'}]}]如果devices.z_id与store.z_id匹配,我需要将“d_id”的值作为数组推送到“store”的字典中,并添加到名为“DID”的新字段中。我尝试了以下方法:{$a

mongodb - 如何更快地执行此 mongoDB 查找聚合?

我想在Robo3T上运行以下mongoDB查询,但需要很长时间才能得出结果:db.getCollection('check').aggregate([{$match:{$and:[{datetime:{"$gt":newISODate("2019-07-0101:00:10.000Z")}},]}},{$lookup:{from:"workstation",localField:"deviceid",foreignField:"_id",as:"workstation"}},{$unwind:{path:"$workstation",preserveNullAndEmptyArrays

python - 使用 $set 和 aggregate 更新 MongoDB 集合

我需要将timestamp_ms的类型从string更改为double并创建FixedDate字段基于这个新的timestamp_ms字段。然后,将NewDate字段中的时间戳信息更改为ISO日期。我使用了这段代码:collection.update({"FixedDate":{"$exists":False}},[{"$set":{"FixedDate":{"$convert":{"input":"$timestamp_ms","to":"double"}}}},{"$set":{"NewDate":{"$toDate":"$FixedDate"}}}],multi=True)它给出

mongodb - Spring Data MongoDB - 聚合框架 - 组操作中的无效引用

我使用SpringData(1.3.0.RC1)访问我们的MongoDB,对于一些新查询,我想使用聚合框架。在mongoshell中,命令是:db.spotreports.aggregate({"$unwind":"$pd"},{"$group":{"_id":"$pd.PDch","base":{$sum:"$pd.aBL"},"uplift":{$sum:"$pd.up"}}}){"result":[{"_id":5,"base":529133,"uplift":21516},...我使用的Spring代码是:Aggregationagg=Aggregation.newAggreg