0

I have following document structure

{
  "_id":12638gkhF67JKGftyh88,
  "tags":[1,3,5,6,9]
}
.
.
.

I want to search search on the basis where _id matches and tags has value '6'

in PHP, my query will be like

$collection -> find(
  '$and' => array(
     array("_id" => new MongoId("12638gkhF67JKGftyh88")),
     array("tags" => WHAT WOULD BE HERE)
  )
)

I couldn't find anything about this, help me out plz

2 Answers 2

1

Using the in operator

$collection -> find(
'$and' => array(
 array("_id" => new MongoId("12638gkhF67JKGftyh88")),
 array("tags" => array("$in" => "6"))
)
)
Sign up to request clarification or add additional context in comments.

Comments

1

in mongodb there is an operator of in for searching values in arrays - http://docs.mongodb.org/manual/reference/operator/query/in/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.