aggregation-framework

Faceted filters in Mongo DB with for products with multiple options

女生的网名这么多〃 提交于 2019-12-22 16:38:42
问题 we are trying to create call to MangoDB to receive all possible filters for products. I will try to create example of our products First product is Adidas Shoes which have two options to select - colour and size. But for different colours you have different sizes. { id: 1 name: "Adidas Shoes", filters: [ [ { code: "brand", value: "Adidas" }, { code: "colour", value: "white" }, { code: "size", value: 41 } ], [ { code: "brand", value: "Adidas" }, { code: "colour", value: "white" }, { code:

find first of documents for each distinct values for one field

强颜欢笑 提交于 2019-12-22 14:58:37
问题 With a collection of documents with fields field1 , field2 , field3 and so on, I need to find distinct values for field3 for each distinct value of field3 , need to get the first document with each distinct value in field3 For # 1, I could do db.myCollection.distinct("field3") How do I go about #2 ? Sample Collection: [ { "field1": 11, "field2": "toyota", "field3": "camry" }, { "field1": 22, "field2": "toyota", "field3": "corolla" }, { "field1": 33, "field2": "toyota", "field3": "camry" }, {

$lookup from Multiple Collections, and nested output

别说谁变了你拦得住时间么 提交于 2019-12-22 13:58:09
问题 I have a multiple collections , I used the separate collection & foreign key approach , and I want to join this collections to build a nested collections. this is my schemas of collections: const SurveySchema = new Schema({ _id:{ type: Schema.ObjectId, auto: true }, name: String, enabled: {type: Boolean, Default: true}, created_date:{type: Date, Default: Date.now}, company: {type: Schema.Types.ObjectId, ref: 'Company'},}); const GroupSchema = new Schema({ _id:{ type: Schema.ObjectId, auto:

Node.js + Mongoose.js How to get sum of orders are placed in a month or a week?

陌路散爱 提交于 2019-12-22 11:22:30
问题 I find out the aggregate framework, but how to get the doucments in a month or a week? I am tring to calculate how many orders are placed in a week or in a month. The documents are like this: { "_id" : ObjectId("53834167b54a3b22f0079e2c"), "createdDate" : ISODate("2014-05-26T13:28:07.942Z"), "__v" : 0 }, { "_id" : ObjectId("53834167b54a3b22f0079e2c"), "createdDate" : ISODate("2014-05-28T09:28:07.942Z"), "__v" : 0 } All I want to have is how many orders are placed in a month according the

MongoDB: how to compare $size of array to another document item?

二次信任 提交于 2019-12-22 10:20:05
问题 MongoDB: how to do something like this, both in mongo console and via JavaScript, Node.js: db.turnys.find( { users:{$size:seats } } ) turnydb.turnys looks like this: [ { "gId": "5335e4a7b8cf51bcd054b423", "seats": 2, "start": "2014-03-30T14:23:29.688Z", "end": "2014-03-30T14:25:29.688Z", "rMin": 800, "rMax": 900, "users": [], "_id": "533828e1d1a483b7fd8a707a" }, { "gId": "5335e4a7b8cf51bcd054b423", "seats": 2, "start": "2014-03-30T14:23:29.688Z", "end": "2014-03-30T14:25:29.688Z", "rMin": 900

Update on Aggregate in Mongodb

拟墨画扇 提交于 2019-12-22 10:05:53
问题 i am trying to toggle a boolean value inside a object, which is a subdocument, i am having hard time to update a particular object within an array. Document: "_id" : ObjectId("54afaabd88694dc019d3b628") "Invitation" : [ { "__v" : 0, "ID" : ObjectId("54af6ce091324fd00f97a15f"), "__t" : "USER", "_id" : ObjectId("54b4ceb50fc380001bea1752"), "Accepted" : false }, { "__v" : 0, "ID" : ObjectId("54afac5412f5fdcc007a5c4d"), "__t" : "USER", "_id" : ObjectId("54b4cebe0fc380001bea1753"), "Accepted" :

python - sort mongodb by the value of one key

偶尔善良 提交于 2019-12-22 09:02:50
问题 I have a collection with below data structure: [{name: "123", category: "A"}, {name: "456", category: "B"}, {name: "789", category: "A"}, {name: "101", category: "C"}] I want to be able to sort them according to the value of category , by specifying which comes first. For example, sorting the query in the order of B->C->A, the result would yield: [{name: "456", category: "B"}, {name: "101", category: "C"}, {name: "123", category: "A"}, {name: "789", category: "A"}] Is there any good way of

Mongodb aggregation pipeline size and speed issue

淺唱寂寞╮ 提交于 2019-12-22 08:10:05
问题 I'm trying to use a mongodb aggregation query to join($lookup) two collections and then distinct count all the unique values in the joined array. *Note: I don't necessarily know what fields(keys) are in the metaDataMap array. And I don't want to count or include fields that might or might not exist in the Map. So that's why the aggregation query looks like it does. So my two collections look like this: events- { "_id" : "1", "name" : "event1", "objectsIds" : [ "1", "2", "3" ], } Objects { "

Project an element returned with “$arrayElemAt”

房东的猫 提交于 2019-12-22 06:47:04
问题 Forgive me if I confuse some terminology here, but I'm performing a join operation in an aggregation using the '$lookup' operator as shown here: db.collection('items').aggregate([{$match: {}}, { $lookup: { from: 'usr', localField: 'usr._id', foreignField: '_id', as: '__usr' } }, { $project: { info: 1, timestamp: 1, usr: { "$arrayElemAt": [ "$__usr", 0 ] } } }], (err, result) => { res.json(result); db.close(); }); I'm performing a projection on the aggregation result, and I'm using '

Increasing memory limit for mongodb aggregate jobs

大憨熊 提交于 2019-12-22 06:46:15
问题 Based on the aggregation pipeline docs, "any single aggregation operation consumes more than 10 percent of system RAM, the operation will produce an error." - http://docs.mongodb.org/manual/core/aggregation-pipeline-limits/ Is there any way of increasing this limit? I have also set allowDiskUse: true (so the error is no longer an issue), but would like to use more RAM to improve performance. Background: I am running a large aggregate job on mongodb on about 100 million entries. It is