mongodb-aggregation

Converting mongo array to object with key-value pair

我的梦境 提交于 2019-12-12 10:53:39
问题 I have a mongo document that contains an array of Strings, and I need to convert this particular array of strings into an array of object containing a key-value pair. Below is my curent appraoch to it. { "_id" : ObjectId("57e3720836e36f63695a2ef2"), "platform" : "A1", "available" : { "Community" : { "attributes" : { "type" : { "values" : [ "well-known", "simple", "complex" ], "defaultValue" : "well-known" }, [......] } Current Query: templateAttributes.find({platform:"V1"}).map(function(c){ /

MongoDB Aggregation command to Java code

让人想犯罪 __ 提交于 2019-12-12 02:42:36
问题 This is my mongodb shell command: db.dais_employee.aggregate([ { "$redact": { "$cond": { "if": { "$gt": [ { "$subtract": [ "$modifiedon", "$createdon" ] }, 1000 * 60 * 60 * 24 ] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ]) which works fine. I need to work this MongoDB command in java and I need help for using MongoDB Aggregation framework with java driver. When I am trying to run this command using java driver: AggregateIterable<Document> iterable = collection.aggregate(asList( new

How to filter data between two times from hh:mm to hh:mm in mongoDB

我的梦境 提交于 2019-12-11 01:17:28
问题 Mongoose var filter = {}; filter.strBillDate = { "$gte": new Date(req.params.fromdate), "$lt": new Date(req.params.todate) }; return Sales .aggregate([{ $match: filter }, { "$project": { "strBillNumber": 1, "strBillAmt": 1, "store_id": 1, "strBillDate": 1, "hourPart": { "$hour": "$strBillDate" }, "minutePart": { "$minute": "$strBillDate" }, } }, { "$match": { "hourPart": { "$gte": fromhour, "$lte": tohour } } }]) .exec(function(err, salesdata) { if (!err) { return res.send(salesdata); } });

How to apply condition on $lookup result in mongoDB?

限于喜欢 提交于 2019-12-10 02:58:36
问题 With the reference of my previous question, I have a question about $lookup with add some conditions. You may get enough reference about question from below link description. Photo: {_id: 1, photo_name: '1.jpg', photo_description: 'description 1', album_id: 1, flag:1 }, {_id: 2, photo_name: '2.jpg', photo_description: 'description 2', album_id: 1, flag:1 }, {_id: 3, photo_name: '3.jpg', photo_description: 'description 3', album_id: 1, flag:1 }, {_id: 4, photo_name: '4.jpg', photo_description:

Elasticsearch and subsequent Mongodb queries

梦想的初衷 提交于 2019-12-08 06:36:10
问题 I am implementing search functionality using Elasticsearch. I receive "username" set returned by Elasticsearch after which I need to query a collection in MongoDB for latest comment of each user in the "username" set. Question: Lets say I receive ~100 usernames everytime I query Elasticsearch what would be the fastest way to query MongoDB to get the latest comment of each user. Is querying MongoDB 100 times in a for loop using .findOne() the only option? (Note - Because latest comment of a

Elasticsearch and subsequent Mongodb queries

☆樱花仙子☆ 提交于 2019-12-06 15:41:06
I am implementing search functionality using Elasticsearch. I receive "username" set returned by Elasticsearch after which I need to query a collection in MongoDB for latest comment of each user in the "username" set. Question: Lets say I receive ~100 usernames everytime I query Elasticsearch what would be the fastest way to query MongoDB to get the latest comment of each user. Is querying MongoDB 100 times in a for loop using .findOne() the only option? (Note - Because latest comment of a user changes very often, I dont want to store it in Elasticsearch as that will trigger retrieve-change

Query for latest version of a document by date in mongoDB

血红的双手。 提交于 2019-12-05 23:54:09
I am trying to find a mongoDB script which will look at a collection where there are multiple records of the same document and only provide me with the latest version of each document as a result set. I cannot explain it in English any better than above but maybe this little SQL below might explain it further. I want each document by transaction_reference but only the latest dated version ( object_creation_date ). select t.transaction_reference, t.transaction_date, t.object_creation_date, t.transaction_sale_value from MyTable t inner join ( select transaction_reference, max(object_creation

mongodb group and subgroup counts

﹥>﹥吖頭↗ 提交于 2019-12-05 08:33:10
I have the following document type { "_id" : "-fA2845ORqeyMUItKXfqZw", "user" : "553247ffdc8a4ade4bb09c5e", "state" : 2, "metadata" : { "language" : "en-US" }, "pipeline" : { "api" : "http://localhost:4000", "provider" : 0 }, "ingest" : { "mimetype" : "audio/mpeg", "size" : 92794268, "client" : "computer", "isWriteable" : true }, "assembly" : { "ok" : "ASSEMBLY_EXECUTING", "message" : "The assembly is currently being executed.", "assembly_id" : "23f29680b32911e59d48f358b85e112d", "parent_id" : null, "template_id" : null, "bytes_received" : 1265, "bytes_expected" : null, "upload_duration" : 0

How to apply condition on $lookup result in mongoDB?

て烟熏妆下的殇ゞ 提交于 2019-12-05 03:56:22
With the reference of my previous question, I have a question about $lookup with add some conditions. You may get enough reference about question from below link description. Photo: {_id: 1, photo_name: '1.jpg', photo_description: 'description 1', album_id: 1, flag:1 }, {_id: 2, photo_name: '2.jpg', photo_description: 'description 2', album_id: 1, flag:1 }, {_id: 3, photo_name: '3.jpg', photo_description: 'description 3', album_id: 1, flag:1 }, {_id: 4, photo_name: '4.jpg', photo_description: 'description 4', album_id: 2, flag:0 }, {_id: 5, photo_name: '5.jpg', photo_description: 'description

group in mongo excluding null values

China☆狼群 提交于 2019-12-04 02:46:57
问题 I have mongo query which does the group operation on the documents. I have almost got the expected results except that I want to refine the results without empty or null values. Currently my query looks like this: db.productMetadata.aggregate([{$group:{"_id":{"color":"$productAttribute.colour","gender":"$productAttribute.gender"},"count" : {$sum : 1}}}]); And the results looks something like this: { "_id" : { "color" : "BLUE", "gender" : "MEN" }, "count" : 1 } { "_id" : { }, "count" : 4 } { "