node.js - Find documents by an array of objects -
i want create query in mongodb to find documents , array of objects math document property.
i have documents:
{meta: {prop1: "hi1", prop2: "ho1"}}, {meta: {prop1: "hi2", prop2: "ho2"}}, {meta: {prop1: "hi3", prop2: "ho3"}}, {meta: {prop1: "hi1", prop2: "ho2"}}
i want find documents meta
property 1 of exact objects in array:
[ {prop1: "hi1", prop2: "ho1"}, {prop1: "hi2", prop2: "ho2"} ]
desired result documents:
{meta: {prop1: "hi1", prop2: "ho1"}}, {meta: {prop1: "hi2", prop2: "ho2"}}
but not:
{meta: {prop1: "hi1", prop2: "ho1"}}, {meta: {prop1: "hi2", prop2: "ho2"}}, {meta: {prop1: "hi1", prop2: "ho2"}}
use $in operator.
collection.find({ meta: { $in: [ { prop1: 'hi1', prop2: 'ho1'}, { prop1: 'hi2', prop2: 'ho2'} ] } })
Comments
Post a Comment