How to manually create a DBRef using pymongo?

I want to create a DBRef manually to add an extra field to it. However, when I try to convey the following:

{'$ref': 'projects', '$id': '1029412409721', 'project_name': 'My Project'}

Pymongo raises an error:

pymongo.errors.InvalidName: key '$id' must not start with '$'

It would seem that pymongo reserves $for a special key, making me wonder if it is even possible to do what I'm trying to do?

+3
source share
1 answer

You probably do not want to create them manually, since keys in DBRefs need to be ordered. We could add an instance of creating a DBRef instance with custom kwargs, although that would solve your problem. If you write jira for this, we can release it in an upcoming release.

+3
source

Source: https://habr.com/ru/post/1750364/


All Articles