I have a mongoDB database having many documents. Its structure is:
"Tenant_Details": {
"$Tenant_Name": {
"Tenant Name" : "$Tenant_Name",
"Tenant Address" : "$Tenant Address",
"Tenant Contact" : "$ Tenant number",
"System_ID" : "$System_ID",
"$System_ID": [
"List of assigned device numbers for $System_ID"
]
}
}
Here $ sign indicates the variable data. But I am confused about looping through the Tenant Details for getting the "List of assigned device numbers". I won't be knowing the Tenant_Name, so I need to look at all documents of Tenant details matching the device numbers for System_ID.
How do I loop without knowing the Tenant_Name?
EDIT1: I tried by storing the list of the Tenant Names in the DB and by looping through the list it worked. I tried like this:
TenantNames = db.find_one() # list of tenant Names
TenantDetailsObj = db.find_one()
SystemID = 1
deviceNumber = 2
for names in TenantNames:
if deviceNumber in TenantDetailsObj.get(name).get(str(SystemID)):
GotData = 1
But in this the Tenant name was known hence looping was easy, but I am not getting without knowing Tenant Name how do I loop?