Tag: spring mongodb

mongodb mongoTemplate用一些标准获得不同的字段

我的MongoDB json结构是 { “_id” : “122134231234234”, “name” : “Total_pop”, “description” : “sales category”, “source” : “public”, “dataset” :”d1″ }, { “_id” : “1123421231234234”, “name” : “Total_pop”, “description” : “sales category”, “source” : “public”, “dataset” :”d1″ }, { “_id” : “12312342332423343”, “name” : “Total_pop”, “description” : “sales category”, “source” : “private”, “description” : “d1” } 我需要获得不同的数据集的集合,其中source是公共的。 […]

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中的条件匹配的所有子文档(使用spring)

我有一个MongoDB存储来自不同传感器的数据。 它具有以下结构: { “_id” : 1, “sensorName” : “Heart Rate”, “samplePeriod” : 1000, “data” : [ { “timestamp” : NumberLong(“1483537204046”), “dataPoints” : [ 68 70 ] }, { “timestamp” : NumberLong(“1483537206046”), “dataPoints” : [ 68 70 ] } ] } { “_id” : 2, “sensorName” : “Ambient Light”, “samplePeriod” : 500, “data” : [ { […]