Tag: aggregation framework

聚合项目组通过Spring Data提取日,月和年

要直接,我该怎么做: group._id = { year: { $year : [{ $subtract: [ “$timestamp”, 25200000 ]}] }, month: { $month : [{ $subtract: [ “$timestamp”, 25200000 ]}] }, day: { $dayOfMonth : [{ $subtract: [ “$timestamp”, 25200000 ]}] } }; 用spring数据 我已经尝试了这个和其他一些forms并没有成功 Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(c), Aggregation.project(“programa”, “custo”, “duracao”, “dataHora”) .andExpression(“dataHora”).minus(25200000).extractDayOfMonth().as(“dia”) .andExpression(“dataHora”).minus(25200000).extractMonth().as(“mes”) .andExpression(“dataHora”).minus(25200000).extractYear().as(“ano”), Aggregation.group(“programa”, “ano”, “mes”, […]

使用Morphia返回匹配的数组元素

我正在寻找一种方法,在提供一些conditions后过滤掉给定List of Object所有对象。 例如 A级 @Entity(value = “tbl_A”) public class A { private String notes; @Embedded private List sampleObject; ….getter and setter … } B级 @Embedded public class SampleObject { private boolean read; private boolean sentByBot; … getter and setter … } 现在,我只想收集已将sentByBot参数设置为true sentByBot 。 我使用以下方法: Query queryForA = datastore.find(A.class); queryForA.field(“sampleObject.sentByBot”).equal(false).retrievedFields(true, “sampleObject.sentByBot”); 上面的代码给出了包含sampleObject.sentByBot true和false的objects的完整列表。 我也尝试filter方法即 […]

Spring – mongodb – aggregation – ‘cursor’选项是必需的

执行以下聚合管道: public void getMostLikedItems () { UnwindOperation unwind = Aggregation.unwind(“favoriteItems”); GroupOperation group = Aggregation.group(“favoriteItems”).count().as(“likes”); SortOperation sort = Aggregation.sort(Sort.Direction.DESC, “likes”); Aggregation aggregation = newAggregation(unwind, group, sort); DBObject result = mongoTemplate.aggregate(aggregation, “users”, LikedItem.class).getRawResults(); } 抛出以下exception: com.mongodb.MongoCommandException: Command failed with error 9: ‘The ‘cursor’ option is required, except for aggregate with the explain argument’ on server localhost:27017. The […]

mongotemplate聚合与条件

我有一个文件看起来像这样的集合: { _id: “545b9fa0dd5318a4285f7ce7”, owner: “admin”, messages: [ { id: “100”, status: “sent”, note: “” }, { id: “100”, status: “pending”, note: “” }, { id: “101”, status: “sent”, note: “” }, { id: “102”, status: “sent”, note: “” }, { id: “101”, status: “done”, note: “” } ] } (这只是一个简短的例子,在我的例子中,子数组非常大) 我需要查询集合并获取特定文档的一些统计信息。 所以在这个例子中,如果我查询具有id:“545b9fa0dd5318a4285f7ce7”的doucment,我应该得到这个结果: { sent: […]

MongoDB中的计算分组字段

对于MongoDB文档中的这个示例,如何使用MongoTemplate编写查询? db.sales.aggregate( [ { $group : { _id : { month: { $month: “$date” }, day: { $dayOfMonth: “$date” }, year: { $year: “$date” } }, totalPrice: { $sum: { $multiply: [ “$price”, “$quantity” ] } }, averageQuantity: { $avg: “$quantity” }, count: { $sum: 1 } } } ] ) 或者一般来说,我如何按计算字段分组?

在mongodb聚合中查找

以下bson是personaddress集合: { “id” : “123456”, “name” : “foo”, “address” : [ { “local” : “yes”, “location” : [ { “place” : { “_id”:”VZG”, }, “place_lat” : “18”, “place_lan” : “83”, }, { “place” : { “name” : “kerala”, “district” : “palakkad”, “pincode” : “5203689”, }, “place_lat” : “18”, “place_lan” : “83”, } ] } ] […]

MongoDB $ aggregate $ push Java Spring Data中的多个字段

我有一个mongo聚合组查询: db.wizard.aggregate( { $group: { _id: “$title”, versions: { $push: {version:”$version”, author:”$author”, dateAdded:”$dateAdded”}} } }) 我需要在Java Spring-Data-MongoDB中使用此查询,我目前的解决方案如下所示: Aggregation agg = Aggregation.newAggregation( Aggregation.group(“title”). push(“version”).as(“versions”) ); 问题是我不知道如何为push方法添加更多字段(版本,作者,dateAdded)。 是否可以使用Spring-Data-MongoDB?