当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript connection.on方法代码示例

本文整理汇总了TypeScript中mongoose.connection.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript connection.on方法的具体用法?TypeScript connection.on怎么用?TypeScript connection.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mongoose.connection的用法示例。


在下文中一共展示了connection.on方法的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: 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

示例4: 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

示例5: _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

示例6: disconnect

    /**
     * Mongodb disconnect
     */
    public disconnect(): void {

        Mongoose.disconnect((err) => {
            Logger.info(err);
        });

        // Mongoose.connection.close(function() {
        //      Logger.info("Mongoose connection disconnected");
        //      callback();
        //     // process.exit(0);
        // });

        /** When the connection is disconnected */
        Mongoose.connection.on("disconnected", function() {
            Logger.info("Mongoose default connection disconnected");
        });
    }
开发者ID:nshahm,项目名称:generator-microservice-template,代码行数:20,代码来源:Mongodb.ts

示例7:

//Handle logout request middleware
app.get('/logout',function(req:any,res){
    req.session["isLogin"]=false;
    res.render("form",{"message":JSON.stringify('')});
})


//DataBase connection
////mongodb://test:test@ds061345.mongolab.com:61345/portfolioapp
//mongodb://localhost/portfolioapp
var dbUri="mongodb://localhost/portfolioapp";

mongoose.connect(dbUri);
mongoose.connection.on('connected',function() {
    console.log('Database connected');
})
mongoose.connection.on('error',function(err) {
    console.log(err);
})

//Database Schema
var blogSchema=mongoose.Schema({
    "name":{type:String},
   "message":{type:String },
   "status":{type:Boolean ,default:false},
   "sendOn":{type:Date,default:Date.now()}
});

//Database Model 
var Blog=mongoose.model('blogs',blogSchema);
开发者ID:InnovativeLabs067,项目名称:MEAN-Apps,代码行数:30,代码来源:app.ts

示例8: function

import * as mongoose from "mongoose";

let connectionString = process.env.MONGO_URL || "mongodb://db:27017/devopsfun";

mongoose.connect(connectionString);
mongoose.connection.on("error", function() {
  console.log("MongoDB Connection Error. Please make sure that MongoDB is running.");
  process.exit(1);
});

export default mongoose;
开发者ID:remojansen,项目名称:DevOpsfun,代码行数:11,代码来源:db.ts

示例9: express

/**
 * Create Express server.
 */
const app = express();



/**
 * Connect to MongoDB.
 */
(mongoose as any).Promise = global.Promise
mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI)

mongoose.connection.on('error', () => {
  // console.log('MongoDB connection error. Please make sure MongoDB is running.')
  process.exit()
})


/**
 * Express configuration.
 */
app.set('port', process.env.PORT || 3000)
app.set('views', path.join(__dirname, './views'))
app.set('view engine', 'pug')

// app.locals.encodeHTML = (str: string) => {
//   return _.escape(str)
// }

app.use(compression())
开发者ID:linkFly6,项目名称:Said,代码行数:31,代码来源:server.ts

示例10: function

app.set('view engine','ejs');

//setting middleware
app.use(express.static(path.join(__dirname,'/public')));
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({extended:true}));
app.use(session({
  genid: function(req) {
    return (Date.now().toString()) // use UUIDs for session IDs 
  },
  secret: '123456789'
}));

//connection verification
mongoose.connection.on('connected',function() {
    console.log('Connection status : Database connected');
})

mongoose.connection.on('error',function(err) {
    console.log('Connection status : fail \n' +err);
})

var todoSchema=mongoose.Schema({
    "email":{type:String, required:true},
    "task":{type:String, required:true},
    "description":{type:String, required:true},
    "createdOn":{type:Date,default:Date.now()}
})

var userSchema=mongoose.Schema({
   "username":{type:String , required:true},
开发者ID:Parkash067,项目名称:My_drive,代码行数:31,代码来源:app.ts


注:本文中的mongoose.connection.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。