MongoDB全文搜索——目前尚不支持针对特定field的搜索

简介:
复制代码
> db.articles.createIndex( { subject: "text" } )
{
        "createdCollectionAutomatically" : true,
        "numIndexesBefore" : 1,
        "numIndexesAfter" : 2,
        "ok" : 1
}
> db.articles.insert(
...    [
...      { _id: 1, subject: "coffee", author: "xyz", views: 50 },
...      { _id: 2, subject: "Coffee Shopping", author: "efg", views: 5 },
...      { _id: 3, subject: "Baking a cake", author: "abc", views: 90  },
...      { _id: 4, subject: "baking", author: "xyz", views: 100 },
...      { _id: 5, subject: "Caf Con Leche", author: "abc", views: 200 },
...      { _id: 6, subject: ".......", author: "jkl", views: 80 },
...      { _id: 7, subject: "coffee and cream", author: "efg", views: 10 },
...      { _id: 8, subject: "Cafe con Leche", author: "xyz", views: 10 }
...    ]
... )
BulkWriteResult({
        "writeErrors" : [ ],
        "writeConcernErrors" : [ ],
        "nInserted" : 8,
        "nUpserted" : 0,
        "nMatched" : 0,
        "nModified" : 0,
        "nRemoved" : 0,
        "upserted" : [ ]
})
> db.articles.find( { $text: { $search: "coffee" } } )
{ "_id" : 2, "subject" : "Coffee Shopping", "author" : "efg", "views" : 5 }
{ "_id" : 7, "subject" : "coffee and cream", "author" : "efg", "views" : 10 }
{ "_id" : 1, "subject" : "coffee", "author" : "xyz", "views" : 50 }> db.articles.find( { $text: { $search: "\"coffee shop\"" } } )
{ "_id" : 2, "subject" : "Coffee Shopping", "author" : "efg", "views" : 5 }
> db.articles.find( { $text: { $search: "\"coffee\" \"shop\"" } } )
{ "_id" : 2, "subject" : "Coffee Shopping", "author" : "efg", "views" : 5 }
> db.articles.find( { $text: { $search: "coffee shop" } } )
{ "_id" : 2, "subject" : "Coffee Shopping", "author" : "efg", "views" : 5 }
{ "_id" : 7, "subject" : "coffee and cream", "author" : "efg", "views" : 10 }
{ "_id" : 1, "subject" : "coffee", "author" : "xyz", "views" : 50 }
复制代码

参考:https://docs.mongodb.com/manual/reference/operator/query/text/















本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6801264.html,如需转载请自行联系原作者


相关文章
|
存储 自然语言处理 NoSQL
D7 Elasticsearch-Mongodb(搜索记录)
D7 Elasticsearch-Mongodb(搜索记录)
152 0
|
监控 NoSQL MongoDB
MongoDB全文检索: 助力快速精准的文本搜索
MongoDB全文检索: 助力快速精准的文本搜索
1047 0
|
存储 NoSQL Ubuntu
百度搜索:蓝易云【如何在Ubuntu上安装MongoDB?】
请注意,具体的命令和步骤可能因MongoDB的版本和Ubuntu的版本而有所不同。请根据你使用的具体版本进行相应的调整。
230 3
|
NoSQL 安全 Linux
百度搜索:蓝易云【CentOS7安装MongoDB教程】
这些是在CentOS 7上安装MongoDB的基本步骤。根据您的需求和具体环境,可能还需要进行其他配置和调整。请确保在进行任何与网络连接和安全相关的操作之前,详细了解您的网络环境和安全需求,并采取适当的安全措施。
287 0
|
NoSQL MongoDB Docker
百度搜索:蓝易云【Scrapy框架之Docker安装MongoDB教程。】
现在,你已经成功在Scrapy框架中使用Docker安装并配置了MongoDB。你可以在Scrapy爬虫中使用MongoDB进行数据存储和处理。
354 0
|
NoSQL Linux MongoDB
百度搜索:蓝易云【如何在 RHEL 8 或者 CentOS 8 上安装 MongoDB?】
以上是在RHEL 8或CentOS 8上安装MongoDB的基本步骤。安装完成后,您可以使用MongoDB的客户端工具连接到MongoDB服务器,并开始使用它进行数据库操作。希望这些步骤能够帮助您在RHEL 8或CentOS 8上成功安装MongoDB。
217 0
|
存储 NoSQL Java
使用 MongoDB 搜索附近的人|学习笔记
快速学习使用 MongoDB 搜索附近的人
776 0
使用 MongoDB 搜索附近的人|学习笔记
|
NoSQL 关系型数据库 MySQL
DLA支持分析MongoDB/RDS只读实例
在对Mysql,MongoDB等数据库系统进行分析时,经常面临的一个问题是在进行分析查询时如何避免对实时业务产生影响,也就是OLAP负载和OLTP负载隔离的问题。针对这个问题,阿里云数据湖团队一直在努力优化,提供满足不同场景的解决方案。
920 0
DLA支持分析MongoDB/RDS只读实例

推荐镜像

更多