Thursday, 11 October 2018

Mongoose find document by key whose value is a complex object

I am using Mongoose to do a search for documents in a collection based on the criteria described below:

Document:

{
    "_id": {
        "$oid": "5a60621e20205641281f7c2f"
    },
    "key1": [
        {
            "available": true,
            "required": true,
            "name": "Name-1"
        },
        {
            "available": true,
            "required": true,
            "name": "Name-2"
        },
        {
            "available": true,
            "required": true,
            "name": "Name-3"
        }
    ],
    "__v": 0
}

I want to perform a search based on property key1. So basically what I want to do is pass the json object as search pattern below and get the result as the document above in return

[
        {
            "available": true,
            "required": true,
            "name": "Name-1"
        },
        {
            "available": true,
            "required": true,
            "name": "Name-2"
        },
        {
            "available": true,
            "required": true,
            "name": "Name-3"
        }
    ]

Is there a way that I can achieve this?



from Mongoose find document by key whose value is a complex object

No comments:

Post a Comment