Question

I am executing a query with mongoengine. As a result I want to get a list of ids to continue working with them.

When I use .scalar("id") I get a queryset with objects ids

  Test.objects.filter(is_deleted=False).scalar("id")    --> [ObjectId(kasdfji93jiasdkfj),....]

For my following raw query i need this Format [kasdfji93jiasdkfj,....]

 { field: { $in: [kasdfji93jiasdkfj,....] } }

Does anybody know an approch without iterating through the queryset to build this list?

Thanks a lot!

Was it helpful?

Solution

You have to convert the ObjectId's to strings and that means iterating the queryset.

Why do you need them to be strings in the $in query - its more efficient to store ObjectIds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top