aggregation-framework

Count items from another document in mongodb aggregation

徘徊边缘 提交于 2020-12-12 21:34:25
问题 I have two distinct documents as Accounts [ {_id:1, name:'xyz'}, {_id:2, name:'abc'}, {_id:3, name:'def'}, {_id:4, name:'pqr'}, ] and Responses [ {_id:01, accountId:2, questionId: 0001, res: true}, {_id:02, accountId:2, questionId: 0002, res: true}, {_id:03, accountId:1, questionId: 0003, res: false}, {_id:03, accountId:3, questionId: 0002, res: false}, {_id:03, accountId:2, questionId: 0003, res: false}, ] How can I count number of true and false responses for an individual account while

Count items from another document in mongodb aggregation

好久不见. 提交于 2020-12-12 21:26:38
问题 I have two distinct documents as Accounts [ {_id:1, name:'xyz'}, {_id:2, name:'abc'}, {_id:3, name:'def'}, {_id:4, name:'pqr'}, ] and Responses [ {_id:01, accountId:2, questionId: 0001, res: true}, {_id:02, accountId:2, questionId: 0002, res: true}, {_id:03, accountId:1, questionId: 0003, res: false}, {_id:03, accountId:3, questionId: 0002, res: false}, {_id:03, accountId:2, questionId: 0003, res: false}, ] How can I count number of true and false responses for an individual account while

Count items from another document in mongodb aggregation

点点圈 提交于 2020-12-12 21:24:24
问题 I have two distinct documents as Accounts [ {_id:1, name:'xyz'}, {_id:2, name:'abc'}, {_id:3, name:'def'}, {_id:4, name:'pqr'}, ] and Responses [ {_id:01, accountId:2, questionId: 0001, res: true}, {_id:02, accountId:2, questionId: 0002, res: true}, {_id:03, accountId:1, questionId: 0003, res: false}, {_id:03, accountId:3, questionId: 0002, res: false}, {_id:03, accountId:2, questionId: 0003, res: false}, ] How can I count number of true and false responses for an individual account while

MongoDB - Find documents matching certain condition for unknown field keys

我们两清 提交于 2020-12-12 12:14:38
问题 How can I query a MongoDB collection to find documents with a structure as below? The documents have a field called thing which is a subdocument, and the keys for this field are a form of ID number which will generally not be known by the person writing the query (making dot notation difficult and I assume impossible). { "_id" : 3, "_id2" : 234, "thing": { "2340945683": {"attribute1": "typeA", "attribute2": "typeB", "attribute3": "typeA" }, "349687346": {"attribute1": "typeC", "attribute2":

MongoDB - Find documents matching certain condition for unknown field keys

谁说胖子不能爱 提交于 2020-12-12 12:13:38
问题 How can I query a MongoDB collection to find documents with a structure as below? The documents have a field called thing which is a subdocument, and the keys for this field are a form of ID number which will generally not be known by the person writing the query (making dot notation difficult and I assume impossible). { "_id" : 3, "_id2" : 234, "thing": { "2340945683": {"attribute1": "typeA", "attribute2": "typeB", "attribute3": "typeA" }, "349687346": {"attribute1": "typeC", "attribute2":

Querying localized data in MongoDB

一笑奈何 提交于 2020-12-12 04:03:54
问题 Having data 'localized' like this: { "cs": [ { "cID": "00001", "title": { "en": "title en1", "de": "title de1" }, "desc": { "en": "desc en1", "de": "desc de1" }, "startDate": 20210801, "endDate": 20210809, "numDays": 8 }, { "cID": "00002", "title": { "en": "title en2", "de": "title de2" }, "desc": { "en": "desc en2", "de": "desc de2" }, "startDate": 20210701, "endDate": 20210715, "numDays": 14 } ] } What would be the best way to query this taking user locale (passed to query as param) into

Querying localized data in MongoDB

橙三吉。 提交于 2020-12-12 04:02:12
问题 Having data 'localized' like this: { "cs": [ { "cID": "00001", "title": { "en": "title en1", "de": "title de1" }, "desc": { "en": "desc en1", "de": "desc de1" }, "startDate": 20210801, "endDate": 20210809, "numDays": 8 }, { "cID": "00002", "title": { "en": "title en2", "de": "title de2" }, "desc": { "en": "desc en2", "de": "desc de2" }, "startDate": 20210701, "endDate": 20210715, "numDays": 14 } ] } What would be the best way to query this taking user locale (passed to query as param) into

In MongoDB, how do I perform a $geoWithin query as part of an aggregation pipeline that utilizes $lookup?

爱⌒轻易说出口 提交于 2020-12-12 02:00:10
问题 I'm trying to use an aggregation pipeline to determine whether a specific territory has specific territories that match $geoWithin . Each territory has a geojson geometry object that is indexed appropriately. I'm not sure I am using let properly in this pipeline or if there is a way to coerce MongoDB into recognizing the parameters as appropriate geojson . I get the following error with the pipeline below: unknown GeoJSON type: { type: "$$type", coordinates: "$$coords" } const

In MongoDB, how do I perform a $geoWithin query as part of an aggregation pipeline that utilizes $lookup?

隐身守侯 提交于 2020-12-12 01:59:10
问题 I'm trying to use an aggregation pipeline to determine whether a specific territory has specific territories that match $geoWithin . Each territory has a geojson geometry object that is indexed appropriately. I'm not sure I am using let properly in this pipeline or if there is a way to coerce MongoDB into recognizing the parameters as appropriate geojson . I get the following error with the pipeline below: unknown GeoJSON type: { type: "$$type", coordinates: "$$coords" } const

Get all possible combinations from array in MongoDB aggregation 🚀

血红的双手。 提交于 2020-12-06 16:22:58
问题 How to do aggregation ( $group ) by the same values ​​from the array? Not all at once, but few or all, if any. I can do $group by one word, but I also need all possible variations... Collection example: {"keywords": ["gta", "distribution", "keys"]} {"keywords": ["gta", "online", "moto", "races"]} {"keywords": ["gta", "online", "samp"]} Result example: "gta" - 3 matches "online" - 2 matches "gta online" - 2 matches 回答1: You could use $reduce to extract all combinations of pairs from an array.