php - Using AND on same key in mongodb -
i have key in document structure follow:
"tag": [ { "schemename": "http:\/\/somesite.com\/categoryscheme2", "name": "test tag2", "value": 1, "slug": "test_tag2" }, { "schemaname": "http:\/\/somesite.com\/categoryscheme3", "name": "test tag3", "value": 1, "slug": "test_tag3" } ]
now, inputs tag=test_tag2andtest_tag3
. how can write query this? tried iterate through loop didnt got results.
correct me if wrong don't need $and
or $elemmatch
, instead:
$mongodb->collection->find(array('tags.slug'=>array( '$in' => array('test_tag2','test_tag3'))))
should work, however, if english suggests second read does, can use $all
in place of $in
. ensure root documents must have slugs in them.
Comments
Post a Comment