I have a collection in my MongoDB and have data in it. I need to write a query that fetches a specific field based on the condition from an array of objects in my collection.
collection each row contains :
mouseClicks :[
{
"url":"abc.com",
"moves":{},
"sitedata":""
},
{
....
....
} ,...
]
I want to fetch sitedata field that matches the specified url.
mongodb version : 4.2.0
db.log5.find({'mouseClicks':{$elemMatch :{'url':"first.html"}}},{'mouseClicks.sitedata':1} )
I got all the sitedata values from all the documents which are not matching the condition. I expect the output is to fetch only the sitedata for the corresponding url.