Sunday, 15 May 2011

MongoDB returns no results in python -



MongoDB returns no results in python -

why mongodb homecoming results in shell not in python.

shell:

> db.posts.find({ body: /html/ }).count() 5524

python code:

query = {"body": '/html/'} r = mo_db.posts.find(query) print r.count() > 0

all other queries work fine, find() works fine. there way handle slashes?! tested r'/html/' , u'/html/'.

you're querying value string, not actual regular look object. /.../ syntax javascript syntax sugar constructing regex, in python need re module.

try this:

import re pattern = re.compile("html") query = {"body": pattern} r = mo_db.posts.find(query) print r.count()

python mongodb

No comments:

Post a Comment