當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。