I’m trying to store one documents objectID into another as an attribute (linking) but mongo keeps giving me this error. What is wrong with this line’s syntax?
for u in self.request.db.lyrics.find():
u['forSong'] = self.request.db.song.find({}, {'_id': 1})
self.request.db.lyrics.save(u)
The problem is that the result of find method is a cursor, not a list of objects
is cursor, not an object.
So you must convert returned cursor to list for doing your task:
That will save list of dicts like {‘_id’: object-id} into “forSong” field.
To actually receive list of object ids you must make further conversion, e.g: