(callback)
| 13 | } |
| 14 | |
| 15 | function connect(callback) { |
| 16 | mongoose.Promise = global.Promise; |
| 17 | mongoose.set('useNewUrlParser', true); |
| 18 | mongoose.set('useFindAndModify', false); |
| 19 | mongoose.set('useCreateIndex', true); |
| 20 | |
| 21 | let config = yapi.WEBCONFIG; |
| 22 | let options = {useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true}; |
| 23 | |
| 24 | if (config.db.user) { |
| 25 | options.user = config.db.user; |
| 26 | options.pass = config.db.pass; |
| 27 | } |
| 28 | |
| 29 | options = Object.assign({}, options, config.db.options) |
| 30 | |
| 31 | var connectString = ''; |
| 32 | |
| 33 | if(config.db.connectString){ |
| 34 | connectString = config.db.connectString; |
| 35 | }else{ |
| 36 | connectString = `mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`; |
| 37 | if (config.db.authSource) { |
| 38 | connectString = connectString + `?authSource=${config.db.authSource}`; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | let db = mongoose.connect( |
| 43 | connectString, |
| 44 | options, |
| 45 | function(err) { |
| 46 | if (err) { |
| 47 | yapi.commons.log(err + ', mongodb Authentication failed', 'error'); |
| 48 | } |
| 49 | } |
| 50 | ); |
| 51 | |
| 52 | db.then( |
| 53 | function() { |
| 54 | yapi.commons.log('mongodb load success...'); |
| 55 | |
| 56 | if (typeof callback === 'function') { |
| 57 | callback.call(db); |
| 58 | } |
| 59 | }, |
| 60 | function(err) { |
| 61 | yapi.commons.log(err + 'mongodb connect error', 'error'); |
| 62 | } |
| 63 | ); |
| 64 | |
| 65 | autoIncrement.initialize(db); |
| 66 | return db; |
| 67 | } |
| 68 | |
| 69 | yapi.db = model; |
| 70 |
no outgoing calls
no test coverage detected