Posts

Showing posts with the label aggregation-framework

Mongodb: reverse document tree as a view (using C# driver)

Image
Clash Royale CLAN TAG #URR8PPP Mongodb: reverse document tree as a view (using C# driver) I'm trying the following (simplistic scenario): I have two documents that look like this (cinema has timeslots, timeslot has a movie): { "_id":"5b5dd8932dc7aa1e180f8c23", "Name":"Cinema 1", "TimeSlots":[ { "Start":"2018-07-29T16:00:00.000Z", "End":"2018-07-29T18:30:00.000Z", "Movie":{ "_id":"5b5dd8932dc7aa1e180f8c24", "Name":"Movie 1" } }, { "Start":"2018-07-29T15:00:00.000Z", "End":"2018-07-29T17:15:00.000Z", "Movie":{ "_id":"5b5dd8932dc7aa1e180f8c25", "Name":"Movie 2" } } ] } { "_id":"5b5dd8932d...

How to make lookup between two collections when an item in an array exists in the other collection?

Image
Clash Royale CLAN TAG #URR8PPP How to make lookup between two collections when an item in an array exists in the other collection? In Lookup with a pipeline, I would like to get the linked records from an array in the parent document. // Orders [{ "_id" : ObjectId("5b5b91a25c68de2538620689"), "Name" : "Test", "Products" : [ ObjectId("5b5b919a5c68de2538620688"), ObjectId("5b5b925a5c68de2538621a15") ] }] // Products [ { "_id": ObjectId("5b5b919a5c68de2538620688"), "ProductName": "P1" }, { "_id": ObjectId("5b5b925a5c68de2538621a15"), "ProductName": "P2" } , { "_id": ObjectId("5b5b925a5c68de2538621a55"), "ProductName": "P3" } ] How to make a lookup between Orders and Products when Products field is an array ! Products I tried this query db.getCollection...

In Mongodb How to Give two different $match

In Mongodb How to Give two different $match In Db I have some sample data: Object 1 "_id" : ObjectId("5b5934bb49b") "payment" : { "paid_total" : 500, "name" : "havi", "payment_mode" : "cash", "pd_no" : "PD20725001", "invoices" : [ { "invoice_number" : "IN11803831583" } ], "type" : "Payment" } Object 2 "_id" : ObjectId("5b5934ee31e"), "patient" : { "invoice_date" : "2018-07-26", "invoiceTotal" : 2000, "pd_no" : "PD20725001", "type" : "Invoice", "invoice_number" : "IN11803831583" } Note : All the Data is In same Collection As the above shown data I have many objects in my database. How can I get the Sum from the data above of invoiceTotal and sum of paid_...