Value error on running find_one query

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

@Prasad_Saya thanks for replying,

Here is the document:

Screenshot from 2020-08-29 18-02-14

I want to search this using _id which is automatically generated. the time_data.user_id is in the string formate.

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

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.