草庐IT

group_value

全部标签

java - 如何使用 spring 数据在 mongo 聚合中构建 $group 的组合 _id 属性?

我在mongodb文档中找到了这个mongo命令: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}}}])当使用springdata的Aggregation时,很容易通过调用Aggregation.group(Feild...

mongodb - 获取 Mongo DB $group 中的特定元素

我正在使用Mongo2.6和zips示例数据进行测试,我希望能够在查询和使用聚合框架时获得纬度或经度,这是我拼凑的一个示例:db.zips.aggregate([{$project:{_id:1,city:1,loc:1}},{$unwind:'$loc'},{$group:{"_id":"$_id","city":{$first:"$city"},"lat":{$first:"$loc"}}}])$slice做的正是我想要的,而不是$unwind和$group因为我只想从数组中提取特定字段,但你不能在聚合框架中使用它我看得出来。所以$unwind似乎在我分组时做类似的事情,问题是$f

mongodb - Angular 5 + Material 设计 : <mat-select> how to set the default value?

{{category.name}}我尝试了很多东西。文档、github上的一些错误报告仍然没有解决我的问题。我只想预设一个默认值...默认值存储在一个名为:resource.categoryName的变量中。这些选项来自mongodb的集合,这些存储在类别[]中。Thispictureshowstheclosedmat-select(nodefaultvalueshown,butitshould...)openedmat-selectHereismy.ts.Theimportantlineis"this.resource.categoryName=this.subdoc['name']

javascript - mongodb 聚合 $sort by field value closest to some value

我想使用aggregation$sortpricevalueclosestto92对以下聚合输出进行排序我一直用到的聚合db.units.aggregate([{$match:{category:'a'}},{$limit:3},{$project:{price:1,name:1,category:1}}]);输出[{'_id':'111','price':100,'name':'abc','category':'a'}{'_id':'222','price':90,'name':'efg','category':'a'}{'_id':'333','price':80,'name':'

node.js - Mongoose - CastError : 'Cast to undefined failed for value "[object Object ]"at path "trainers"

我是node.js的新手,所以这可能是一个愚蠢的错误。我有一个像这样的mongodb模式:seller_schema=mongoose.Schema({name:String,email:String,trainers:[{type:mongoose.Schema.Types.ObjectId,ref:'trainers'}]});seller_collection=db.model('seller',seller_schema);trainer_collection是:trainer_schema=mongoose.Schema({trainer_fname:String,train

MongoDB 聚合 - $group by date 即使不存在

我已经有一个如下所示的查询:{$match:{"when":{$gt:newDate(ISODate().getTime()-1000*60*60*24*30)}}},{$project:{"year":{$year:"$when"},"month":{$month:"$when"},"day":{$dayOfMonth:"$when"}}},{$group:{_id:{year:"$year",month:"$month",day:"$day"},"count":{$sum:1}}},{$sort:{_id:1}}结果是这样的:{"_id":{"year":2015,"month":

javascript - 在 $group mongodb 之后获取公共(public)元素

我有一些交易数据如下:[{"_id":ObjectId("5d319aa8df4026532fe5036f"),"transaction":ISODate("2018-10-16T04:00:07.000Z"),"cardnumber":"1000000000020356"},{"_id":ObjectId("5d319aa8df4026532fe5035x"),"transaction":ISODate("2018-10-16T04:00:07.000Z"),"cardnumber":"1000000000020358"},{"_id":ObjectId("5d319aa8df402

mongodb - 获取 listOfStrings 中 subDocument.value 所在的所有项目

我在dotnetcore2.1中使用MongoDB.Drivernuget包。我正在尝试返回集合中的文档列表,其中子文档字段等于我拥有的列表中包含的任何项目。理想情况下,我需要在C#语法中为dotnetcore2.1的MongoDB.Drivernuget包使用它。文档{“_id”:“e29628a65e914c1e91b3fd9cbf6f2353”,“启用”:真,“名称”:“Document123”,"DisplayName":"一些文档",“描述”:“一些描述”,“数据”:[“姓”,“电子邮件”,“名”,“邮政编码”],“项目”:[{“_id”:“1”,“名字”:“鲍勃”},{“_

mongodb - 没有 $unwind 的 $group 内部数组值

我想按指定字段的相同值对数组中的对象进行分组并生成一个计数。我有以下mongodb文档(不存在不相关的字段)。{arrayField:[{fieldA:value1,...otherFields},{fieldA:value2,...otherFields},{fieldA:value2,...otherFields}],...otherFields}下面是我想要的。{arrayField:[{fieldA:value1,...otherFields},{fieldA:value2,...otherFields},{fieldA:value2,...otherFields}],newA

MongoDb 将 $group '_id' 空值聚合为不同的

我有以下数据结构:{"_superBill":{"$oid":"568b250ba082dfc752b20021"},"paymentProviderTxID":"aaaa","transactionRaw":"abcdef","commissionRate":0.2,"visitDate":{"$date":"2016-12-26T13:04:05.544Z"}},{"_superBill":{"$oid":"568b250ba082dfc752b20021"},"paymentProviderTxID":"bbbb","transactionRaw":"abcdef","commi