Created
September 11, 2020 00:24
-
-
Save ctrlaltdylan/683d9897f9e18a6d1ceaef5ec4548f04 to your computer and use it in GitHub Desktop.
Mongod Text query with compound index
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
// Create the searchable checks index | |
db.collection("checks") | |
.createIndex({ shopName: 1, firstName: "text", lastName: "text" }) | |
.then((res) => { | |
console.log("checks text index created"); | |
}) | |
.catch((err) => console.log("checks text index creation failed", err)); | |
const checks = await db | |
.collection("checks") | |
.find({ | |
shopName, | |
'$text': { | |
'$search': ctx.query.searchTerm | |
} | |
}) | |
.sort({ createdAt: -1 }) | |
.toArray(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment