當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mongoose.createConnection函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。