I'm trying to write a filter to replicate the data to another CouchDB server. As part of filter, I would like to pick only certain parts of the document, based on the filter. The fields
in Selector
can fetch the root nodes, but how can I pick nested elements?
These are sample docs structure:
{
"_id" : "1231212",
"name" : "",
"a" : [
{
"x" : "123",
"y": "123" ,
"z" : 123"",
"l" : [1, 2, 3]
},
{
"x" : "456",
"y": "456" ,
"z" : "456",
"l" : [4, 5, 6]
}
]
}
{
"_id" : "34534545",
"name" : "",
"a" : [
{
"x" : "222",
"y": "333" ,
"z" : 444"",
"l" : [6, 7, 8]
},
{
"x" : "66",
"y": "66" ,
"z" : "888",
"l" : [2, 9, 7]
}
]
}
Is it possible to put a selector to pick fields, which is an element from array. In above Doc structure, I can filter the data with element in Array "l", but how I can only display that element.
{
"selector": {
"a": {
"$elemMatch": {
"l": {
"$in": [
4
]
}
}
}
},
"fields": [
"name",
"a"
]
}
if I use this selector, which give both elements of "a" array. But I need only the filtered element.
For the above filter, I'm expecting:
{
name : "",
"a" : [
{
"x" : "456",
"y": "456" ,
"z" : "456",
"l" : [4, 5, 6]
}
]
}
what I'm getting is
{
"_id" : "1231212",
"name" : "",
"a" : [
{
"x" : "123",
"y": "123" ,
"z" : 123"",
"l" : [1, 2, 3]
},
{
"x" : "456",
"y": "456" ,
"z" : "456",
"l" : [4, 5, 6]
}
]
}
Is it possible?