What Dan said is exactly right but I just wanted to make it clear the
original error isn't actually with PyMongo.
> This python error means that you have no local variable named v.
Here's an example:
Python 2.7.1 (r271:86832, Jun 15 2011, 18:14:54)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> v
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'v' is not defined
On Aug 26, 8:40 am, Dan Crosta <
dcro...@gmail.com> wrote:
> This python error means that you have no local variable named v.
>
> You can't add a field with no value to a BSON document (nor to a Python dictionary, as we see in your error). If you meant to add it with a null BSON value, you can use:
>
> coll.update({'_id': record_id}, {'$set': {'v': None, 'b': None, 'd': None}})
>
> Python's None is translated by pymongo to a BSON null. You can see a table of the other type mappings athttp://
api.mongodb.org/python/current/api/bson/son.html?highlight=nul...
>
> - Dan
>
> On Aug 26, 2011, at 11:14 AM, Martin Wirz wrote:
>
>
>
>
>
>
>
> > I have a collection of documents that look like:
>
> > {u'a': 492.0, u'c': 1, u'l': {u'lat': 116.331763, u'long': 39.937213},
> > u'u': 130, u't': 1230803098.0, u'_id':
> > ObjectId('4e5518be93585711374dfba5')}
>
> > Now, I would like to add a field v to that document using the update()
> > function in PyMongo:
>
> > coll.update({'_id': record_id}, {"$set": {'v': v, 'b': b, 'd':d}},
> > upsert=False)
>
> > This, however, returns the following error message: NameError: name
> > 'v' is not defined.
>
> > I found this:
http://stackoverflow.com/questions/4372797/how-do-i-update-a-mongo-do...