These are chat archives for Automattic/mongoose

Apr 2016
Kevin Whitman
Apr 09 2016 04:31
Hey. I am new to Mongo and Mongoose. With the connection pool, what happens if it's set to 5 and 5 queries fire at once? Will it open new connections on demand or wait until those connections are no longer in used?
Vlado Tesanovic
Apr 09 2016 10:12
@og01 If i understand you right, you are creating mongo connection for each schema right now? Create one file, and export mongo connection there, than in each schema/model import that mongo.

@og01 In schema definition, you can specify unique as part of key

name: {
 type: String,
 unique: true

Or you can at schema level create unique mongo index,

userSchema.index({ email: 1 }, { unique: true });
Apr 09 2016 12:00
@vladotesanovic Thanks, I was doing this, I found the documentation in the end, I saw an example somewhere where they had supplied dropdups (now depreciated in mongo), and my unique index was failing to be created. I had to manually remove the index, restart mongoose and everything was fine.
@vladotesanovic bit of a pain though, I'll have to put something in to drop all indexes after the schema changes
As for my other query, I found a module that did 90% of what I was planning, and I can see from the way they were doing it that I was thinking of it all wrong. I wanted to implement the RESTfull routes based off my Schemas and was planning on implementing the role based permissions in mongoose middleware, I can see now that its express middleware that does the heavy lifting, and I can see how to do it now
Vlado Tesanovic
Apr 09 2016 12:18
@og01 cool, on what module you are referring? You can always drop indexes trough mongo cli
Apr 09 2016 12:33
@vladotesanovic yeah in my testing I dropped the indexes using mongo cli, but I need to work out ongoing how to progressively upgrade the schema. The module I found was called mongoose-express-router