Skip to content Skip to sidebar Skip to footer

MongoDB: Query Array For 'true' Value At Index N

So I have this collection containing a field 'weekdays' representing weekdays Monday-Sunday (checked or not checked): var collection = [ // work week (Monday to Friday)

Solution 1:

you can use this code

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

and if you want check 2 days:

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

Post a Comment for "MongoDB: Query Array For 'true' Value At Index N"