$exists missing from pymongo driver?

2,015 views
Skip to first unread message

Jorge Vargas

unread,
Oct 5, 2009, 1:33:01 AM10/5/09
to mongod...@googlegroups.com
Hello,

Today I found out about the "exists" operator sadly apparently it is
not supported by pymongo (or I have the wrong syntax).

I upgraded to 1.0 both for pymongo and mongo itself. But I'm still getting.

>>> from pymongo.connection import Connection
>>> connection = Connection()
>>> db=connection.edb
>>> [a for a in db.fooo.find({'name' : {'$exists' :'true'}})]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-i686/egg/pymongo/cursor.py", line 444, in next
File "build/bdist.linux-i686/egg/pymongo/cursor.py", line 419, in _refresh
File "build/bdist.linux-i686/egg/pymongo/cursor.py", line 392, in send_message
pymongo.errors.OperationFailure: database error: invalid $operator: $exists
>>> import pymongo
>>> pymongo.__file__
'/home/elpargo/venvs/e/lib/python2.5/site-packages/pymongo-1.0-py2.5-linux-i686.egg/pymongo/__init__.pyc'


is this a bug or am I doing something wrong?

Nicolas Clairon

unread,
Oct 5, 2009, 4:01:55 AM10/5/09
to mongod...@googlegroups.com
Hi,

"true" must be a python boolean. So try with :

>>> [a for a in db.fooo.find({'name' : {'$exists' :True}})]

Jorge Vargas

unread,
Oct 5, 2009, 8:57:14 AM10/5/09
to mongod...@googlegroups.com
Hello,

Ahh thank you.

That seems to have worked. Odd enough I was almost sure I tried that
before posting. Odd.

Perhaps the driver should be a little more clear about the error.

Is it trying to find a field called "$exists" ? Perhaps a better error
will be "Invalid value for operator $exists 'true' "

Michael Dirolf

unread,
Oct 5, 2009, 8:59:51 AM10/5/09
to mongod...@googlegroups.com
The error message you're seeing isn't from the driver, but from the
server itself. Agreed it could be made a little nicer though.
Reply all
Reply to author
Forward
0 new messages