Created
November 1, 2018 02:15
-
-
Save bangbang93/f2b0989fb8f218efb14886b85332fd68 to your computer and use it in GitHub Desktop.
mongoose-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
import * as Mongoose from 'mongoose' | |
Mongoose.connect('mongodb://localhost/test') | |
Mongoose.set('debug', true) | |
const schema = new Mongoose.Schema({ | |
a: { | |
type: String, | |
} | |
}) | |
schema.index({a: 1}, {unique: true, partialFilterExpression: {$type: 'string'}}) | |
const model = Mongoose.model('t', schema) | |
async function main() { | |
const doc = new model({ | |
a: Math.random().toString() | |
}) | |
await doc.save() | |
} | |
main() | |
.then(() => console.log(123)) | |
.catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment