- Insert test data with column name and description
- > Db.stores.insert (
- ... [
- ... {_id:1, name: "Java Hut", Description: "Coffee and Cakes"},
- ... {_id:2, name: "Burger Buns", Description: "Gourmet Hamburgers"},
- ... {_id:3, name: "Coffee Shop", Description: "Just Coffee"},
- ... {_id:4, name: "Clothes Clothes Clothes", Description: "Discount clothing"},
- ... {_id:5, name: "Java Shopping", Description: "Indonesian Goods"}
- ... ]
- ... )
- Bulkwriteresult ({
- "writeerrors": [],
- "writeconcernerrors": [],
- "ninserted": 5,
- "nupserted": 0,
- "nmatched": 0,
- "nmodified": 0,
- "nremoved": 0,
- "upserted": []
- })
- Built on stores so contains the name column and the description are both text
- > Db.stores.createIndex ({ name: "text", Description: "Text"})
- {
- "createdcollectionautomatically": false,
- "Numindexesbefore": 1,
- "Numindexesafter": 2,
- "OK": 1
- }
- Performing a full-text search will result in keyword segmentation and matching results, which can be measured by a small amount of data.
- > Db.stores. find ({$text: {$search: "java Coffee Shop"}})
- {"_id": 3, "name": "Coffee Shop", "description": "Just Coffee"}
- {"_id": 1, "name": "Java Hut", "description": "Coffee and Cakes"}
- {"_id": 5, "name": "Java Shopping", "description": "Indonesian Goods"}
Advantage: Real-time full-text search.
Do not know how performance, do not support highlighting this display, only in the 3.2+ version is supported Chinese word segmentation.
Under the general understanding, the temporary will not use, later use can read the manual in detail:
https://docs.mongodb.com/manual/text-search/
MongoDB Full-Text search