I have the following sample document saved in my mongodb collection :
{
_id:"3213dsadsa812321",
files: [
{_id: "99300", path:"C:\Filename01.txt"},
{_id: "99301", path:"C:\Filename02.txt"},
{_id: "99302", path:"C:\Filename03.txt"},
{_id: "99303", path:"C:\Filename04.txt"},
]
}
and I have the following array var dynFiles:
[
{_id: "1", path:"C:\folder\textfile01.txt"},
{_id: "2", path:"C:\folder\textfile02.txt"},
{_id: "3", path:"C:\folder\textfile03.txt"},
{_id: "4", path:"C:\Filename04.txt"},
]
is it possible to find if any of the mongodb document objects array path key match any of the dynFiles var path key?
In other words, based on the given above record _id: "99303" in db should be returned as it match the var object array _id: "4".
Expected result:
[ {_id: "99303", path:"C:\Filename04.txt"} ]
After extensive research I wrote the following query but unfortunately it doesn't help much as it compare the document files.path keys with a specific object array key, while I need it to compare files.path with all paths of dynFiles. Thanks in advance for your help and time
{ 'files.path': {$eq: dynFiles.path} }