• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: MongoDB Inner Query

Resolved: MongoDB Inner Query

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have a mongodb document in this format. There are multiple collections of arrays as given here. How do I get all elements where SID = 100.

Answer:

Option 1:
Explained:
  1. Unwind all arrays and nested arrays.
  2. Match only the subobjects with SID:100
  3. Project only the necessary object content

Playground1
Option 2: ( Slightly faster)
Explained:
  1. Unwind the first 3x arrays
  2. Match only documents having at least 1x SID:100 in 4th array
  3. Filter only those from 4th array having SID:100
  4. Unwind the 4th array
  5. Project only the final object we need

Playground2

If you have better answer, please add a comment about this, thank you!

mongodb mongodb-query
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Input Focus between two React Components

02/04/2023

Resolved: linq2db throws exception when filtering by nested collection

02/04/2023

Resolved: Table data is coming as empty in React

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.