aby669
(Abhay Raghuvanshi)
August 29, 2020, 8:57am
1
Hello, Whenever I’m trying to run the find_one query I’m getting this error:
ValueError: [TypeError("'ObjectId' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]
Here is the query that I’m running:
user = users.find_one({
'_id': ObjectId(time_data.user_id)
})
What I’m doing wrong here?
Hello @aby669 , welcome to the community.
Please post sample values of the variable time_data.user_id
and the field _id
of the collection’s document. They need to be of same data type for the query to run without errors.
1 Like
aby669
(Abhay Raghuvanshi)
August 29, 2020, 7:56pm
3
@Prasad_Saya thanks for replying,
Here is the document:
I want to search this using _id
which is automatically generated. the time_data.user_id
is in the string formate.
1 Like
Hi @aby669 , hope you had a good weekend.
Here is an example of such usage; querying a collection by ObjectId
using as string value of it: Querying By ObjectId
1 Like
system
(system)
Closed
September 5, 2020, 10:46am
5
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.