Search code examples
mongodbrestrestheart

Restheart | filter within an array


How do I filter documents if there are sub sets of data (data within arrays) using Restheart

This is a sample JSON

{
    "_id" : ObjectId("58760e53a4c0a73900472eb0"),
    "foods" : [ 
        "root vegetables", 
        "yogurt", 
        "other vegetables"
    ],
    "prices" : [ 
        "$1",
        "$23",
        "$21",
    ],
    "market_ratio" : 0.606299212598425
}

For example I want to get all the documents with foods that includes ```yogurt

I tried ?filter={'foods':['yogurt']}&sort_by=+market_ratio" but it does not return anything.


Solution

  • The correct way:

    ?filter={'foods':{$in:"[yogurt, curd]"}}