I am using a database to find all of a particular instance from this variable:
find_request = mongo.db.requests.find({"request_to": user})
This works and produces a PyMongo cursor for all requests that went to that user (a logged in session user). But I also want to find who that request is from. There are only three items in the dict in the DB.
If I do find_request = list(mongo.db.requests.find({"request_to": user}))
I can see the whole list, but I really want to use from the cursor object in the line above.
I tried request_from=find_request["request_from"]
but this won't work as:
TypeError: index 'request_from' cannot be applied to Cursor instances
So how do I access the request_from within the cursor. The list gives me this information:
[{'_id': ObjectId('abc'), 'request_from': 'test1', 'request_to': 'test2'}, {'_id': ObjectId('xyz'), 'request_from': 'test3', 'request_to': 'test2'}]
In this case, there are only two requests, but there could be many more at any one time (which is why I was reluctant to use the list method).
So, for every request to user: test2, I would like to see who the request is from as a variable.
How would I go about writing from this information?
question from:
https://stackoverflow.com/questions/65952102/how-do-i-get-individual-data-from-a-pymongo-cursor-object 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…