I am newbie to Mongo and trying to figure out how to parse through a complex nested collection.
{
"_id": ObjectId("idVal"),
"Ids": [{
"mar": [{
"se": [{
"gootics": "UA-3-1"
}],
"usery": [{
"fc0633ac-81": [{
"sep": [{
"custS": "",
"promer": "0",
"reaivity": "20",
"stus": "active",
"urlist": "",
"upe": [
"mat "
],
"whlete": ""
}],
"uspt": [{
"cor": "000000",
"foron": "hthp",
"sla": "Join!",
"slie": "httpsg",
"slile": "Jost:",
"suody": "We'll be in touch.",
"sumer": "Awesome!",
"tte": "qumail"
}, {
"cr": "000000",
"refeion": "htve",
"sla": "Go!",
"slige": "httg",
"slle": "Hes",
"slle": "Mm:",
"tte": "rk"
}]
}]
}]
}],
And many more such inner array’ s,
comma separated
}]
}
I need to select the whole part of mar with a mongo query or php.
db.collectionname.find({"Ids" : "mar"}).pretty().
This isn’t resulting anything, just being blank and tried doing db.collectionname.find({}).pretty(), it worked well, got all the results.
I did tried with $elemMatch , $pop etc.
Many solutions are taking very small and easy json files, no one have traversed or parsed through such complex json string. Refer some other standard process or provide your answer.
My need in zist: I will just have one of the Id's value, need to query on the basis of Id. like,
select * from db where Id's == Id I have; in this case it can be mar
Can anyone help me with writing the same query in php?? and printing the output? I am not able to do that. "$ActualData = $collection->find(array("Ids.mar : 1"));" but this isn't printing any value.
var_dump($array);
// Above line is printing this:
array (size=0)
empty
var_dump($ActualData);
//Above line is printing this:
object(MongoCursor)[4]
//not being executed at all:
foreach($ActualData as $doc)
{
echo "Inside it is";
var_dump($doc);
}
echo "Count:".count($ActualData)."\n";
//It does have 1 document
Count:1
db.collection.find({},{"Ids.mar":1})only if you know the keymar. It is strongly recommended not to use dynamic values as keys in your schema.