【发布时间】:2019-08-16 18:08:52
【问题描述】:
我正在使用 mongo-go-driver 并尝试使用文本搜索
我正在创建这样的索引
opts := options.CreateIndexes().SetMaxTime(10 * time.Second)
db.Collection("my_collection").Indexes().CreateMany(
context.Background(),
[]mongo.IndexModel{
{
Keys: bsonx.Doc{{"title", bsonx.Int32(-1)}},
},
{
Keys: bsonx.Doc{{"info.tags", bsonx.Int32(-1)}},
},
},
opts,
)
...在查询时我正在这样做
collection := db.Collection("my_collection")
cur, err := collection.Find(context.Background(), bson.M{ "$text": bson.M{ "$search": query }})
我在调用查询时得到这个
(IndexNotFound) text index required for $text query
exit status 1
【问题讨论】:
标签: mongodb go indexing text-search