MongoDB全文搜索——目前尚不支持针对特定field的搜索
2023-09-14 09:11:55 时间
> 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/
相关文章
- 解决MongoDB 排序超过内存限制的问题
- MongoDB空间索引:解锁无限空间搜索可能(mongodb空间索引)
- 作用持久化存储:利用MongoDB让数据更安全(cimongodb)
- MongoDB实现全文搜索的最佳方案(mongodb全文搜索)
- MongoDB:高效格式化管理(mongodb格式化)
- 过高MongoDB CPU 利用率过高问题排查(mongodb占用cpu)
- MongoDB停止服务:新挑战在前方(mongodb停止服务)
- 分析MongoDB磁盘空间使用情况分析(mongodb磁盘空间)
- 学习MongoDB:查看端口(mongodb端口查看)
- Mongodb报错解决方案快速有效的处理方法(mongodb报错)
- MongoDB中的嵌套文档:各种可能性(mongodb内嵌文档)
- 查询MongoDB精准定位查询,轻松搞定地理位置检索(mongodb地理位置)
- 探究MongoDB多数据源管理之道(mongodb多数据源)
- MongoDB简单启动配置指南(mongodb启动配置)
- Mongodb异步: 改善数据读写效率的有效方法(mongodb异步)
- 无法完成要求,mongodb 8 是什么意思需要进一步的信息才能给出标题。(mongodb8)
- Mongodb启动失败?别慌,这些方法能够帮你解决问题!(mongodb启动失败)
- MongoDB的深度清理,做到一尘不染(mongodb 清理)
- MongoDB分页查询:有效实现数据搜索分页(mongodb 分页查询)