MongoDB : How to find by the sublevels ?

You have a BSON with an array of objects and you want to find by the objects inside so it’s really easy.

Use the ( ‘ ) to make the field definition

Example:

Screen Shot 2015-07-29 at 8.03.31 PM

return Events.find({'sessions.dt_start': { $exists: true },'sessions.dt_start':{$gte:dtStart,$lte:dtEnd}},{sort:{createdAt: -1}});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s