javascript - MongoDB: query Array for 'true' value at index n -


so have collection containing field "weekdays" representing weekdays monday-sunday (checked or not checked):

  var collection = [      // work week (monday friday)     {       weekdays: [true, true, true, true, true, false, false]     },      // weekend     {       weekdays: [false, false, false, false, false, true, true]     },      // ...    ]; 

now, how can query collection find items has true specified weekday?

my first attempt use this:

// $elemmatch...

'weekdays[0]': true // monday 

but did not seem work. i'm out of ideas atm , appreciate help!

you can use code

db.collectin.find({'weekdays.0' : true}) 

and if want check 2 days:

db.collectin.find({$and :      [         {'weekdays.0' : true},         {'weekdays.1' : true}     ] }) 

Comments

Popular posts from this blog

c - CUDA code not processing if block properly -

Android Capture Image From Camera -

oracle11g - get root domain from url Oracle sql regex_substr -