Nisha Patel
Problem
I have a document like this in a collection:
I would like to create a query that returns this:
Looks like a job for aggregate
Start off by:
{ $match: { _id: 123 } }
then maybe
{ $unwind: '$locations' }
Then
{ $project: { _id: 0, location: '$locations'} }
Cool, this gives me:
Now I need a way only to return elements that come after '3-3' (but also keep 3-3). Any ideas?
Solution
Here the approach I took is to $slice the array from index 2 to end of array so to get the position of 3-3 i used $indexOfArray.
Now since locations is sliced there is fewer to $unwind
Answered by: >cmgchess
Credit: >StackOverflow
Blog links:
>How to add a Parsing PHP file in order to get an array of parameters?
>How to correct WordPress site errors after upgrading to PHP 8.2?
>How does Perl match a string containing a dot in PHP?
>How to use PHP to display MySQL results in an HTML table?