I have created a "params" collection in Mongo with the following structure:
{
"_id" : "id1",
"list" : [
{
"type" : "type1",
"subtypes" : [ "id1 subtype11", "id1 subtype12" ]
}
{
"type" : "type2",
"subtypes" : [ "id1 subtype21", "id1 subtype22" ]
}
]
}
{
"_id" : "id2",
"list" : [
{
"type" : "type1",
"subtypes" : [ "id2 subtype11", "id2 subtype12" ]
}
{
"type" : "type2",
"subtypes" : [ "id2 subtype21", "id2 subtype22" ]
}
]
}
I want to get all "subtypes"
for "_id":"id1"
and "type":"type1"
. I found out that the way to do this in the Mongo shell is
db.params.find (
{ $and: [
{"_id" : "id1"},
{"list.type" : "type1"}
] }
)
I have two questions:
- Am I using $and (read: "am I creating the query") the correct way?
- How to parse this query to PHP code properly? I get lost with the syntax :(.
Thank you!