문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top