Search code examples
mongodbpython-2.7full-text-searchmongoengine

Full text search MongoDB/Mongoengine


The new version of MongoDB allows Full Text Search. That part is running fine for me:

db.collection.runCommand('text',{search:<keyword>})

However, I'm not sure that it is possible to run it through python's mongoengine. Does anyone know if there is a way to run "runCommand" with mongoengine or a workaround?

(I'm using mongoengine for my project, I'd hate to have to drop it for pymongo as it would probably mean recoding many things.)

Thanks!


Solution

  • You can use MongoEngine by using pymongo directly eg:

    class MyDoc(Document):
        pass
    
    coll = MyDoc._get_collection()
    coll.database.command(
        "text",
        coll.name,
        search="alice", 
        project={"name": 1, "_id": 0}, 
        limit=10)