I has in MongoDB documents like this:
{
"user": ObjectID("4d71076b26ab7b032800009f")
"pages" : [
{
"name" : "Main",
"content" : [
{
"id" : ObjectId("4d71076b26ab7b052800009f")
},
{
"id" : ObjectId("4d61269b1deb5a3fce000004"),
"link" : "http://example.com"
}
]
}
]}
You can see that the key "pages" is a array with other documents. Now I can query this document with the name of a page and I will get the full document with all pages and other information. I use in python directly pymongo to query the document but now I don't know what the best way is to get a page from the array pages. I think something like this:
def getPage(pageNameWhoINeed):
for page in pages:
if page['name'] == pageNameWhoINeed:
return page
But is this the best way to get a singe page or general a embedded document? All tipps or code snippets are welcome.
Thanks! Jarus