本文整理汇总了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);
});
};
开发者ID:Tzook,项目名称:lul,代码行数:35,代码来源:cloneDb.ts
示例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;
}
开发者ID:saasan,项目名称:mobamas-dojo-server,代码行数:28,代码来源:update.ts
示例3: create
public create () {
this.connection = mongoose.createConnection('mongodb://localhost/tyb');
return this;
}
开发者ID:tybeck,项目名称:portfolio-v2,代码行数:7,代码来源:db.ts
示例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();
});
},
开发者ID:grimcoder,项目名称:ProduceMarket,代码行数:8,代码来源:persistanceMongo.ts
示例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;
}
开发者ID:khacthanh244,项目名称:mocha,代码行数:9,代码来源:dbmongo.ts
示例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);
}
}
开发者ID:igorzg,项目名称:js_cms,代码行数:10,代码来源:mongodb-connection.ts
示例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;
}
开发者ID:khacthanh244,项目名称:mocha,代码行数:10,代码来源:dbmongo.ts
示例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);
}
开发者ID:BugBusterSWE,项目名称:MaaS,代码行数:15,代码来源:mongooseConnection.ts
示例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", {});
}
});
开发者ID:7thCode,项目名称:wmonsin,代码行数:52,代码来源:file_controller.ts
注:本文中的mongoose.createConnection函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论