db.collection1.ensureIndex({post_text:"text"})
post_text是文章字段
法二
db.collection1.createIndex({ "userName": "text", "schoolName": "text" } )
collection1是表名
userName、schoolName是需要上索引的字段
text是索引类型,搜索用text
新版:
db.collection1.find({$text:{$search:"runoob"}})
旧版:
db.collection1.runCommand("text",{search:"runoob"})