I have code in Python/PyMongo like ( code should simulate inner join and all documents from second collection to put (nest inside) in list and add to first appropriate document in Mongo). Idea is to load two collections and pass two fields ( name of fields for connection ) and all documents from second collection with same attribute like in first put in list and add to appropriate document in first collection .
(For example in first collection I have documents with fileds “country”,”population” and in second I have “country” and “car factories” and I want to put ( denormalize ) first collection list of all factories for appropriate country)
for f in first_collection_records:
temp=[]
id=f['_id']
second_collection_records.rewind()
for s in second_collection_records:
if f[field_one]==s[field_two]:
temp.append(s)
f[self.__second_collection_name__]=temp
first_collection_records.update({"_id":id}, f, safe=True)
but I got error ‘Cursor’ object has no attribute ‘update’. What I done wrong ?
first_collection_recordsis apymongo.cursor.Cursorobject. It’s the result you get when you calldb.first_collection.find(). You need to callupdateon your originalcollectionobject: