CouchDB document:
"members": [
{
"name": "Mark",
"age": 35,
},
{
"name": "Bill",
"age": 32,
}
]
DB Query from PouchDB using PouchDB-Find:
db.createIndex({
index: {fields: [
'_id',
'members.[].name'
]}
}).then(() => {
db.find({
'selector': {
'_id': { '$gt': null },
'members': {
'$elemMatch': {
'name': {'$eq': 'Bill'}
}
}
},
'fields': [
'members'
]
}).then((result) => {
console.log(result)
}).catch((err) => {
console.log(err)
})
})
The result I get from the above query is the Members array as the whole. But I need to get only the below when I request "name" as "Bill" not the complete array.
{
"name": "Bill",
"age": 32,
}
I did try the fields section in the query but I am unable to find what should be mentioned to get what I want.
selector: {debut: {$gt: null}}
withselector: {debut: {$eq: 1990}}
This is what I am looking for, Can this be achieved with Mango Query if so how to design the DB like shown in the example. If not, I will go with the Map/Reduce query like you have advised. Thanks. – Ostrom