In my MongoDB docs 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β are an array with other documents. Now I can request this document with the name of the page, and I will receive a complete document with all pages and other information. I use pymongo directly in python to request a document, but now I donβt know how best to get the page from the pages of the array. 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 separate page or a common inline document? All hints or code snippets are welcome.
Thanks! Jarus
Jarus source share