-->

Tuesday, December 2, 2014

how to query mongo and match subdocuments

Untitled Document.md

Imagine that a collection called recipes in your mongodb has entries with the following structure:

{
    "ingredients" : {
        "dairy" : 0,
        "vegetables" : [ ]
    },
}

If you want to match subdocuments into this collection it is actually easier that it seems:

 db.recipes.find({ "ingredients.dairy" : "gwiyomi_sherlocked"}).count()

No comments:

Post a Comment