Using mongoTemplate in java Spring I tried this, but I don't keep document structure
Document as:
{
A :'a',
B :'b',
C : [
{
name:'cat' , type :'animal'
},
{
name:'jonh' , type :'human'
}
]
}
I want to keep document structure and filter c.type = 'animal' like below
Result example :
{
A :'a',
B :'b',
C : [
{
name:'cat' , type :'animal'
},
]
}
I think you are looking for this query where the document is not modified except for the filtering elements into
Carray wheretypeis notanimal.So using MongoTemplate you can try something like this (not tested):