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


TypeScript mongoose.connection類代碼示例

本文整理匯總了TypeScript中mongoose.connection的典型用法代碼示例。如果您正苦於以下問題:TypeScript connection類的具體用法?TypeScript connection怎麽用?TypeScript connection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了connection類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: resolve

    return new Promise<DatabaseObject>((resolve, reject) => {
      mongoose.connect(uri, config)

      mongoose.connection.once('connected', () => {
        logger.info('database connection: success')

        resolve({
          alert: AlertModel,
          attachment: AttachmentModel,
          connection: mongoose.connection,
          delivery: DeliveryModel,
          logger: logger,
          order: OrderModel,
          place: PlaceModel,
          product: ProductModel,
          stock: StockModel,
          tokenSalt: config.tokenSalt,
          user: UserModel
        })
      })

      mongoose.connection.on('error', (err) => {
        logger.error(`database error: ${err}`)
        if (! this.isResolved) {
          reject(err)
        }
      })

      mongoose.connection.on('disconnected', () => {
        logger.info('database connection: ended')
      })
    })
開發者ID:chipp972,項目名稱:stock_manager_api,代碼行數:32,代碼來源:index.ts

示例2: connectMongo

 private connectMongo() {
     let connect = () => mongoose.connect(process.env.MONGO_URL);
     mongoose.connection.on('disconnected', connect);
     mongoose.connection.on('error', err => {
         Logger.errorLog(err);
     });
     connect();
 }
開發者ID:jgkim7,項目名稱:blog,代碼行數:8,代碼來源:app.ts

示例3: async

module.exports = async (context, myBlob) => {
//export async function run (context, myBlob) {

    context.funcId = context.executionContext.invocationId;
    context.log(`ProcessId: ${context.funcId}`);

    try {
        mongoose.connect(process.env.MONGOLAB_URI, configs.mongoose);
        const rows: any = await readCsv(context);
        const entities  = await posRepo.getPosSales(rows);

        const errors = await posRepo.validation(entities, context);
        context.log(`${context.bindingData.name}ファイル: Number of lines appears error is ${errors.length}`);

        if (errors.length == 0) {
            const reservations = await getCheckins(entities, context);
            await posRepo.setCheckins(entities, reservations).then(async (docs) => {
                
                await posRepo.saveToPosSales(docs, context).then(async () => {
                    await posRepo.mergeFunc(context);
                });
            });
        } else {
            Logs.writeErrorLog(context, errors.join("\n"));
        }
        mongoose.connection.close();
    } catch (error) {
        context.log(error);
        Logs.writeErrorLog(context, `${context.bindingData.name}ファイル` + "\n" + error.stack);
    }
}
開發者ID:motionpicture,項目名稱:ttts-functions,代碼行數:31,代碼來源:index.ts

示例4: init

    static init():void {
      const URL = (process.env.NODE_ENV === 'production') ? process.env.MONGOLAB_URI : dbConst.localhost;

      mongoose.connect(URL);
      mongoose.connection.on('error', console.error.bind(console, 'An error ocurred with the DB connection: '));

    }
開發者ID:kieranfraser,項目名稱:sonard,代碼行數:7,代碼來源:db.conf.ts

示例5: function

process.on('SIGINT', function () {/////this function will run jst before app is closing
    console.log("app is terminating");
    mongoose.connection.close(function () {
        console.log('Mongoose default connection closed');
        process.exit(0);
    });
});
開發者ID:MUMARA,項目名稱:UmrSalesmenAppLogoutCompleteNoConsoles3,代碼行數:7,代碼來源:index.ts

示例6: getCheckins

/**
 * //connect into mongoose to get checkins datas got it from previous step
 * @param conds Array
 * @param context Azure function of variable
 */
async function getCheckins (conds, context) {
    mongoose.connect(process.env.MONGOLAB_URI, configs.mongoose);
    const entities = await mongoose.model('Reservation')
        .find({ $or: conds },{checkins: true, payment_no: true, seat_code: true, performance_day: true}).exec()
        .then(docs => docs.map( doc => {
            
            doc.entry_flg = 'FALSE';
            doc.entry_date = null;

            if (doc.checkins.length >= 1) {
                doc.entry_flg = 'TRUE';
                doc.entry_date = doc.checkins[0].when.toISOString();
            }

            return '(' + [
                `'${doc.payment_no}'`
                , `'${doc.seat_code}'`
                , `'${doc.performance_day}'`
                , `'${doc.entry_flg}'`
                , doc.entry_date !== null ? `'${doc.entry_date}'` : `NULL`].join(',') + ')';
        }));

    mongoose.connection.close();
    return entities;
}
開發者ID:motionpicture,項目名稱:ttts-functions,代碼行數:30,代碼來源:index.ts

示例7: after

after((done) => {
  // required because https://github.com/Automattic/mongoose/issues/1251#issuecomment-65793092
  mongoose.models = {};
  mongoose.modelSchemas = {};
  mongoose.connection.close();
  done();
});
開發者ID:eastmaels,項目名稱:v2.api.utopian.io,代碼行數:7,代碼來源:user.test.ts

示例8: connect

    /**
     * Mongodb connection
     */
    public connect(error, callback) {

        Mongoose.connect(this.dburl, this.options);

        /** CONNECTION EVENTS */
        /** When successfully connected */
        Mongoose.connection.on("connected", function() {
            Logger.info("Mongoose connection open");
            callback();
        });

        /** If the connection throws an error */
        Mongoose.connection.on("error", function(err) {
            Logger.info("Mongoose default connection error: " + err);
            error(err);
        });
    }
開發者ID:nshahm,項目名稱:generator-microservice-template,代碼行數:20,代碼來源:Mongodb.ts

示例9: config

    private config() {
        this.app.use(Middleware.configuration);

        mongoose.connection.once('open', () => {
            console.log('Connected to Mongoose at', environment.mongoConnectionString);
        });

        mongoose.connect(environment.mongoConnectionString);
    }
開發者ID:fedoranimus,項目名稱:typescript-mean-stack,代碼行數:9,代碼來源:server.ts

示例10: _initializeDatabaseConnection

  private _initializeDatabaseConnection(test: boolean): void {
    winston.info("Initializing database connection");

    mongoose.connection.on("open", function(): void {
      winston.info("Database connection initialized");
    });

    mongoose.connection.on("error", function(): void {
      winston.error("Unable to connect to the database");
    });

    if (test) {
      mongoose.connect(`mongodb://${config.get("dbConfig.host")}:${config.get("dbConfig.port")}/${config.get("test.dbConfig.dbName")}`);
    }
    else {
      mongoose.connect(`mongodb://${config.get("dbConfig.host")}:${config.get("dbConfig.port")}/${config.get("dbConfig.dbName")}`);
    }
  }
開發者ID:guedjm,項目名稱:StickItWebServer,代碼行數:18,代碼來源:StickItServer.ts


注:本文中的mongoose.connection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。