Search code examples
javascriptjsonmongodbnedb

Searching inside an object in NeDB/MongoDB


First of all, I am using feathers client together with nedb and I followed this documentation.

So I have a json structured like this:

{
    personal: {
        name: 'Robert'
    }
},
{
    personal: {
        name: 'Mark'
    }
},
{
    personal: {
        name: 'Jester'
    }
}

And I want to search 'Robert'. My code for now looks like this:

users.find({ query: { personal: { name: 'Robert' } } }).then(function (response) {
    console.log(response.data)
}, function(error) {
    console.log(error)
})

But I only get an empty array in my console [].

Am I doing something wrong here?


Solution

  • In mongo nested fields can be generally accessed using the . operator (dot notation)

    Try this code:

    users.find({ query: { 'personal.name': 'Robert' } }).then