报错为: name: 'MongoError’, message: ‘only GSSAPI, PLAIN, MONGODB-X509, SCRAM-SHA-1 or MONGODB-CR is supported by authMechanism’
代码:var mongoose = require(‘mongoose’); var format = require(‘util’).format;
if(process.env.BAE_ENV_APPID){
var host ="mongo.duapp.com";
var port ="8908";
var username ="bfc5c2ab184a479292b3fd20b012a683";
var password ="d1b72bc45df94eb4b05a4ffc9f0416af";
var dbName ="aJZfHIoouaDARdxxYghA";
var constr ="mongodb://"+ username +":"+ password +"@"+ host +":"+ port +"/"+ dbName;
}else{
var constr = “mongodb://localhost/ticket”
var username =null;
var password =null;
}
//constr = "mongodb://localhost/ticket";
var options = { db: { native_parser: true }, server: { poolSize:4, socketOptions: { keepAlive: 1 } }, user: username, pass: password }; db = mongoose.createConnection(); var userSchema = new mongoose.Schema({ name:String, password:String},{ collection : ‘users’ });
db.open(constr,options); var userModel = db.model('users’,userSchema);
function User(user){ this.name = user.name; this.password = user.password; } setInterval(function(){console.log(‘closing db now’);db.close();}, 1000601); setInterval(function(){console.log(‘opening db now’);db.open(constr,options,function(err) { if(err){console.log(err);} });}, 1010601);
db.on('open’,function(){ console.log('connection success open’+’mongooseConnection.readyState :’+db.readyState );
//setTimeout(function(){console.log('closing db now');mongoose.disconnect();}, 1000*60*4);
});
db.on('close’,function(err){ console.log(‘closed’);
});