Last active
August 25, 2016 18:10
-
-
Save djanowski/30c4196e58d47d07499cf6403833b2bd to your computer and use it in GitHub Desktop.
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
const Mongoose = require('mongoose'); | |
Mongoose.Promise = Promise; | |
Mongoose.connect(`mongodb://localhost/test-${Date.now()}`); | |
const PersonSchema = new Mongoose.Schema({ | |
name: { | |
first: { type: String }, | |
last: { type: String } | |
} | |
}); | |
// Set up first version of the text index. | |
PersonSchema.index({ 'name.first': 'text' }); | |
const Person = Mongoose.model('Person', PersonSchema); | |
Person.ensureIndexes() | |
.then(() => { | |
// Set up new version of text index. | |
PersonSchema.index({ 'name.first': 'text', 'name.last': 'text' }); | |
return Person.ensureIndexes(); | |
}) | |
.then(() => { | |
console.log('It worked.'); | |
process.exit(); | |
}) | |
.catch(error => { | |
console.error(error.stack); | |
process.exit(1); | |
}); |
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
{ | |
"name": "mongoose-text-nested-field", | |
"version": "1.0.0", | |
"description": "", | |
"main": "mongoose_text_index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git+ssh://[email protected]/30c4196e58d47d07499cf6403833b2bd.git" | |
}, | |
"author": "", | |
"license": "ISC", | |
"bugs": { | |
"url": "https://gist.github.com/30c4196e58d47d07499cf6403833b2bd" | |
}, | |
"homepage": "https://gist.github.com/30c4196e58d47d07499cf6403833b2bd", | |
"dependencies": { | |
"mongoose": "^4.5.10" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment