本文整理汇总了TypeScript中mongoose.createConnection函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createConnection函数的具体用法?TypeScript createConnection怎么用?TypeScript createConnection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createConnection函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: cloneDb
function cloneDb() {
console.log("Cloning DB...");
const prodDb = mongoose.createConnection(getEnvVariable("dbUrlProd"));
const stagingDb = mongoose.createConnection(getEnvVariable("dbUrl"));
Promise.all([prodDb, stagingDb])
.then(() => stagingDb.db.collections())
.then((collections: Collection[]) => {
let promises = [];
for (let collection of collections) {
if (_.contains(["sessions", "logs", "users", "system.indexes", "objectlabs-system.admin.collections", "objectlabs-system"], collection.collectionName)) {
continue;
}
const promise = collection.find().toArray().then(models => {
let promiseValue: any;
if (models.length === 0) {
promiseValue = Promise.reject(`Collection ${collection.collectionName} was empty!`);
} else {
const prodCollection = prodDb.db.collection(collection.collectionName);
promiseValue = prodCollection.remove({}).then(() => prodCollection.insertMany(models));
}
return promiseValue;
});
promises.push(promise);
}
return Promise.all(promises);
})
.then(() => {
console.log("Successfully updated prod db!");
process.exit();
})
.catch((error) => {
console.log("Had an error", error);
process.exit(1);
});
};
示例2: connectDB
/**
* DBへ接続する
*/
function connectDB() {
console.log('connectDB');
var deferred = Q.defer();
// mongoDBサーバー接続
var db = mongoose.createConnection(process.env.MONGOHQ_URL || config.development.mongoURL);
// 接続完了
db.on('connected', function() {
// 次の処理へdbを渡す
deferred.resolve(db);
});
// 切断
db.on('disconnected', function() {
console.log('disconnected');
});
// エラー時の処理
db.on('error', function(err) {
deferred.reject(err);
});
return deferred.promise;
}
示例3: create
public create () {
this.connection = mongoose.createConnection('mongodb://localhost/tyb');
return this;
}
示例4: require
'salesfilter': (id, callback) => {
var mongoose = require('mongoose');
var db = mongoose.createConnection('mongodb://localhost/ProduceMarket');
models.SaleModel(db).find({_id: id}).exec((err, sets)=> {
callback(err, sets);
db.close();
});
},
示例5: dbApp
function dbApp(config: any) {
let db: any = createConnection(config.mongo.app.uri, config.mongo.options);
db.on('error', (err:any) => {
console.log(`MongoDB connection error: ${err}`);
process.exit(-1);
});
db.Promise = global.Promise;
return db;
}
示例6: afterConstruct
afterConstruct(): void {
this.logger.info("Mongodb connection string", this.connectionStr);
try {
this.mongodb = createConnection(this.connectionStr, {
useNewUrlParser: true
});
} catch (e) {
this.logger.error("Mongodb connection", e);
}
}
示例7: dbLog
function dbLog(config: any) {
let db: any = createConnection(config.mongo.log.uri, config.mongo.options);
db.on('error', (err: any) => {
console.log('MongoDB connect error:\n');
console.log(err);
process.exit(-1);
});
db.Promise = global.Promise;
return db;
}
示例8: constructor
/**
* @description Complete private constructor according to the Singleton
* pattern
* @param connection The parameters for the connection
*/
constructor(connection : MongoConnection) {
if (MongooseConnection.instance) {
throw new Error("Attempt to create two instances of this" +
" Singleton. Please use getInstance() method");
}
let connectionString : string = "mongodb://" + connection.getUser() +
":" + connection.getPassword() + "@" + connection.getHost() + ":" +
connection.getDatabasePort() + "/" + connection.getDatabaseName();
this.connection = mongoose.createConnection(connectionString);
}
示例9: Grid
wrapper.Authenticate(request, response, number, (user:any, response:any) => {
// var conn = mongoose.createConnection("mongodb://" + config.dbaddress + "/" + config.db);
var connection = "mongodb://" + config.dbuser + ":" + config.dbpassword + "@" + config.dbaddress + "/" + config.dbname;
var conn = mongoose.createConnection(connection);
if (conn) {
conn.once('open', (error:any):void => {
if (!error) {
var gfs = Grid(conn.db, mongoose.mongo); //missing parameter
if (gfs) {
conn.db.collection('fs.files', (error:any, collection:any):void => {
if (!error) {
if (collection) {
collection.findOne({filename: request.params.name}, (error:any, item:any):void => {
if (!error) {
if (item) {
collection.remove({filename: request.params.name}, ():void => {
wrapper.SendResult(response, 0, "OK", {});
conn.db.close();
logger.trace("end /file/:name");
});
} else {
conn.db.close();
wrapper.SendWarn(response, number + 1, "not found", {});
}
} else {
conn.db.close();
wrapper.SendError(response, number + 100, error.message, error);
}
});
} else {
conn.db.close();
wrapper.SendFatal(response, number + 30, "no collection", {});
}
} else {
conn.db.close();
wrapper.SendError(response, number + 100, error.message, error);
}
});
} else {
conn.db.close();
wrapper.SendFatal(response, number + 20, "gfs error", {});
}
} else {
conn.db.close();
wrapper.SendError(response, number + 100, error.message, error);
}
});
} else {
wrapper.SendError(response, number + 10, "connection error", {});
}
});