Filter time slot array

Read Formatting code and log snippets in posts and republish your documents. We cannot use them, by cut-n-paste into our system because of the way they are published the quotes are wrong.

Also share what you have tried so far and how it fails to provide the correct results. This will help us avoiding to experiment in a wrong direction.

Without giving too much thought, you could use a $project stage to get the specified day.

Untested snippet

specified_day = "monday"

project_stage = { "$project" : { today : "$schedule." + specified_day } }

collection.aggregate( [ project_stage ] )

But the above will give all schedule.monday array. Using $filter allows you to only keep the appropriate elements.

To filter an array, you need https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/.

$filter : {
  "input" :  "schedule." + specified_day ,
  "as" : "filtered" ,
  "cond" : [ ]
}
1 Like