gpt4 book ai didi

Mongodb 文本搜索和 ID 字段

转载 作者:可可西里 更新时间:2023-11-01 10:32:42 25 4
gpt4 key购买 nike

我想在集合中的多个字段中搜索短语/字符串。我还需要将结果过滤到单个 ID 字段。

例如,在用户集合中搜索“john”

db.users.runCommand( "text", { search: "john" } )

当文档看起来像:

{
"_id" : ObjectId("525d5f3fa385ab082e8b4693"),
"first_name" : "John",
"last_name" : "Doe",
"email" : "john@doe.com",
"account_id" : 1,
"updated_at" : ISODate("2013-10-15T15:29:03.951Z"),
"created_at" : ISODate("2013-10-15T15:29:03.951Z")
}

将结果也过滤到特定 ID 的最佳方法是什么,在上述“account_id”的情况下,所以我只会搜索/返回出现“john”且 account_id 等于“1”的结果?

最佳答案

我相信这是使用过滤器选项完成的:

db.users.runCommand( "text", {
search: "john",
filter: { account_id : 1 }
}
)

或来自文档 - http://docs.mongodb.org/manual/tutorial/limit-number-of-items-scanned-for-text-search/

关于Mongodb 文本搜索和 ID 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19392978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com