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


TypeScript connection.once方法代码示例

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


在下文中一共展示了connection.once方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: configureDB

    //<% if (useDB) { %>
    /**
     * Connecting to database
     */
    configureDB() {
        // Dealing with Database
        const dbName   = '<%= dbName %>';
        //<% if (dbType === 'mongo') { %>
        const mongoURL = `mongodb://${process.env.MONGOHOST ? process.env.MONGOHOST : 'localhost'}/${dbName}`;
        mongoose.connect( mongoURL, { useMongoClient: true } );

        mongoose.connection.once( 'open', () => {
            let Blog = mongoose.model( 'Blog' );
            let User = mongoose.model( 'User' );
            let Post = mongoose.model( 'Post' );

            let userDoc = new User( {
                firstName: 'Tata',
                lastName:  'Toto'
            } );
            let blogDoc = new Blog( {
                name:    'My Blog',
                creator: userDoc._id
            } );
            let postDoc = new Post( {
                author: userDoc._id,
                blog:   blogDoc._id
            } );

            userDoc.save( ( err: Error, user: UserDoc ) => {
                this.debug( user );
            } );

            blogDoc.save( ( err: Error, blog: BlogDoc ) => {
                this.debug( blog );
            } );

            postDoc.save( ( err: Error, post: PostDoc ) => {
                this.debug( post );

                Blog.find( {} ).populate( 'posts creator' ).exec( ( error: Error, blogs: BlogDoc[] ) => {
                    this.debug( blogs );
                } );
            } );
        } );

        /*const store = new MongoDBStore(
         {
         uri: mongoURL,
         collection: 'sessions'
         }
         );
         store.on('error', function (error) {
         // Also get an error here
         });*/
        //<% } %>
    }
开发者ID:flowg,项目名称:Locutus,代码行数:57,代码来源:root.express.ts

示例4: router



router(app);


app.all('/ng-example*', (req, res) => {
	res.sendFile('index.html', {root: pathToNgPublic});
});
app.all('/ng2-example*', (req, res) => {
	res.sendFile('index.html', {root: pathToNg2Public});
});
app.all('/ng-upgrade-example*', (req, res) => {
	res.sendFile('index.html', {root: pathToNgUpgradePublic});
});
app.all('/*', (req, res) => {
	res.sendFile('landing.html', {root: __dirname + '/..'});
});

mongoose.Promise = global.Promise;


mongoose.connect('mongodb://localhost/ng-upgrade-profiles');
mongoose.connection.once('open', () => {
	console.log('Mongoose connected to ng-upgrade-profiles db at "localhost:27017"');
});

app.listen('8787', function listener() {
	console.log('Express app listening at "http://localhost:8787/"');
});

export { mongoose };
开发者ID:cwadrupldijjit,项目名称:ng-1-openwest2016,代码行数:29,代码来源:server.ts

示例5: require

import * as helmet from 'helmet';
import * as morgan from 'morgan';
import * as mongoose from 'mongoose';
import {json, urlencoded} from 'body-parser';

const config = require('../../tradejs.config');
const app = express();
app.listen(config.server.email.port, () => console.log(`\n Email service started on      : 127.0.0.1:${config.server.email.port}`));

/**
 * mongo
 */
mongoose.set('debug', true);
mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
mongoose.connection.once('open', function () {
	console.log('DB connected');
});
mongoose.connect(config.server.email.connectionString);

/**
 * express
 */
app.use(morgan('dev'));
app.use(helmet());
app.use(json());
app.use(urlencoded({extended: false}));
app.use((req, res, next) => {
	res.header('Access-Control-Allow-Origin', '*');
	res.header('Access-Control-Allow-Headers', '_id, Authorization, Origin, X-Requested-With, Content-Type, Accept');
	next();
});
开发者ID:Chegeek,项目名称:TradeJS,代码行数:31,代码来源:app.ts


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