我已经在下面的脚本中编写了textSearchedEnabled=true
,但是出现了语法错误。我不明白如何使用python在mongodb中启用文本搜索。在
import json
import pymongo # pip install pymongo
from bson import json_util # Comes with pymongo
from pymongo import MongoClient
--setParameter textSearchEnabled=true
client = pymongo.MongoClient('mongodb://user:user123@ds033499.mongolab.com:33499/enron')
db = client.enron
mbox = db.mbox
# Create an index if it doesn't already exist
mbox.ensure_index([("$**", "text")], name="TextIndex")
# Get the collection stats (collstats) on a collection
# named "mbox"
print json.dumps(db.command("collstats", "mbox"), indent=1)
# Use the db.command method to issue a "text" command
# on collection "mbox" with parameters, remembering that
# we need to use json_util to handle serialization of our JSON
print json.dumps(db.command("text", "mbox",
search="raptor",
limit=1),
indent=1, default=json_util.default)
通常,textSearch是通过云数据库mongodb.conf启动mongodb时。请参阅:Enable Text Search文档。在
如果用户具有管理权限,也可以通过管理命令运行它:
相关问题 更多 >
编程相关推荐