views:

67

answers:

1

I want to create a DBRef manually so that I can add an additional field to it. However, when I try to pass 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 reserve the $ for the special key, leading me to wonder if it is even possible to do what I'm trying to do?

+2  A: 

Probably don't want to be creating them manually like that, since keys in DBRefs need to be ordered. We could add an option to create a DBRef instance w/ custom kwargs though, which would solve your problem. If you file a jira for this we should be able to get it out in an upcoming release.

mdirolf
Yeah, I used the dict syntax for brevity here. I originally used a SON object which, as far as I can tell, maintains key order. However, the keys still refused to let me use $.
Soviut
http://jira.mongodb.org/browse/PYTHON-133 Feature requested.
Soviut
Gotcha. Maybe we should special case for DBRef to let you create manually, but I think your JIRA case is a better solution. Will try to get that out soon.
mdirolf
The restriction on $ starting a key makes sense, but is probably unnecessary. Perhaps raising a warning rather than an exception, or simply documenting the fact that $ keys are reserved would suffice?
Soviut