Created
December 17, 2016 12:49
-
-
Save romuloctba/64fad52f4e37131f2010dee4e38f855d to your computer and use it in GitHub Desktop.
Text Search in Mongo DB / Busca de Texto no Mongodb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You can only search text if you have text-search indexes. Easy Peasy. | |
// Você só pode buscar por texto se tiver um index (índice) de texto. Fácil pacas. | |
// --- | |
// To create a text index, run: | |
// Para criar um index, rode: | |
// (english example) db.collectionName.createIndex({ fieldName: "text" }); | |
// (portuguese example) db.nomeDaCollection.createIndex({ nomeDoCampo: "text" }); | |
// Ex: Collection "cars", fields "name", "model" | |
db.cars.createIndex({ name: "text", model: "text", brand: "text" }); | |
// now you can search for text | |
db.getCollection('cars').find({ $text : { $search: "chevro" } }); | |
// returns chevrolets car |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment