Add autoIndex: false option to mongoose connections.

This prevents mongoose from auto-creating missing indexes on boot.
This commit is contained in:
Shane Kilkelly 2017-11-22 13:37:57 +00:00
parent bda65c0984
commit 035e0c1213
7 changed files with 31 additions and 13 deletions

View file

@ -2,7 +2,10 @@ mongoose = require('mongoose')
Settings = require 'settings-sharelatex'
logger = require('logger-sharelatex')
mongoose.connect(Settings.mongo.url, server: poolSize: 10)
mongoose.connect(Settings.mongo.url, {
server: {poolSize: 10},
config: {autoIndex: false}
})
mongoose.connection.on 'connected', () ->
logger.log {url:Settings.mongo.url}, 'mongoose default connection open'

View file

@ -73,12 +73,14 @@ applyToAllFilesRecursivly = ProjectSchema.statics.applyToAllFilesRecursivly = (f
_.each folder.folders, (folder)->
applyToAllFilesRecursivly(folder, fun)
ProjectSchema.methods.getSafeProjectName = ->
safeProjectName = this.name.replace(new RegExp("\\W", "g"), '_')
return sanitize.escape(safeProjectName)
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10)
conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
Project = conn.model('Project', ProjectSchema)

View file

@ -30,9 +30,10 @@ ProjectInviteSchema = new Schema(
}
)
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10)
conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
ProjectInvite = conn.model('ProjectInvite', ProjectInviteSchema)

View file

@ -25,11 +25,13 @@ SubscriptionSchema.statics.findAndModify = (query, update, callback)->
this.update query, update, ->
self.findOne query, callback
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10)
conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
Subscription = conn.model('Subscription', SubscriptionSchema)
mongoose.model 'Subscription', SubscriptionSchema
exports.Subscription = Subscription
exports.SubscriptionSchema = SubscriptionSchema
exports.SubscriptionSchema = SubscriptionSchema

View file

@ -6,7 +6,11 @@ ObjectId = Schema.ObjectId
SystemMessageSchema = new Schema
content : type: String, default:''
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10)
conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
exports.SystemMessage = conn.model('SystemMessage', SystemMessageSchema)

View file

@ -64,7 +64,10 @@ UserSchema = new Schema
accessToken: { type: String }
refreshToken: { type: String }
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: 10)
conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
User = conn.model('User', UserSchema)

View file

@ -9,7 +9,10 @@ UserStubSchema = new Schema
last_name : { type : String, default : '' }
overleaf : { id: { type: Number } }
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: 10)
conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
UserStub = conn.model('UserStub', UserStubSchema)