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


TypeScript Db.open方法代码示例

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


在下文中一共展示了Db.open方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: openDB

async function openDB() {
  try {
    await db.open();
    console.log('Connected to mongodb');
  } catch (error) {
    console.error('Error connecting to mongodb.', error);
  }
}
开发者ID:shybyte,项目名称:wahlomat,代码行数:8,代码来源:db.ts

示例2: reject

        return new Promise<mongodb.Db>(function (resolve, reject)
        {
            if (!host)
                return reject(new Error("Please provide a 'host' field in your configuration"));
            if (!port)
                return reject(new Error("Please provide a 'port' field in your configuration"));
            if (!database)
                return reject(new Error("Please provide a 'databaseName' field in your configuration"));

            var mongoServer: mongodb.Server = new mongodb.Server(host, port, opts);
            var mongoDB: mongodb.Db = new mongodb.Db(database, mongoServer, { w: 1 });
            mongoDB.open(function (err: Error, db: mongodb.Db)
            {
                if (err || !db)
                    reject(err);
                else
                    resolve(db);
            });
        });
开发者ID:Webinate,项目名称:modepress-render,代码行数:19,代码来源:MongoCache.ts

示例3: getAll

        public getAll(callback: Function) {
            var url = global.config.appSettings.database.mongodb.host;
            var Db = require('mongodb').Db;
            var Server = require('mongodb').Server;

            var db = new Db('scripter', new Server('localhost', 27017));
            // Establish connection to db
            db.open(function (err: any, db1: any) {
                assert.equal(null, err);
                // Return the information of a all collections, using the callback format
                db.collections(function (err: any, items: any) {
                    assert.ok(items.length > 0);
                    var fitems: any = [];
                    for (var i = 0; i < items.length; i++) {
                        fitems.push(items[i].s.name);
                    }
                    callback(fitems);
                });
            });
        }
开发者ID:gitter-badger,项目名称:nodulus,代码行数:20,代码来源:mongodb.ts

示例4:

//setup mongodb
var dbServer = new mongo.Server(CodeSoar.Server.Config.Get().MONGODB_HOST,
								CodeSoar.Server.Config.Get().MONGODB_PORT);

var db = new mongo.Db(CodeSoar.Server.Config.Get().MONGODB_DB_NAME,
					  dbServer, {auto_reconnect: true, w:1});

//open connection to mongodb and authenticate ourselves.
db.open(function(err, db) {

	if (err)
		throw err;

	db.authenticate(CodeSoar.Server.Config.Get().MONGODB_USERNAME,
					CodeSoar.Server.Config.Get().MONGODB_PASSWORD,
					function (err, result) {

						if (err)
							throw err;

					});

});

//Setup Docs and Changes collections for mongodb
var docsDb;
var changesDb;

db.createCollection('docs');
db.createCollection('changes');
开发者ID:mstauber,项目名称:CodeSoar,代码行数:30,代码来源:codesoar.server.ts

示例5: Server

import {MongoClient, Db, Server, ServerOptions} from 'mongodb';
import * as Rx from "rx";
import {IArticle} from '../models/article';

var o: ServerOptions = {}
var server = new Server('localhost', 27017, o)
var db = new Db('dea', server, { w: 1 });
db.open(function() { });

export function count(title: string): Rx.Observable<number> {
    return Rx.Observable.create((observer: Rx.Observer<number>) => {
        db.collection("articles")
            .count({ title: { $regex: `\\b${title}\\b`, $options: 'i' } }, (err, count) => {
                if (err) { observer.onError(err); }
                observer.onNext(count);
                observer.onCompleted();
            });
    });
}

export function find(title: string): Rx.Observable<IArticle[]> {
    return Rx.Observable.create((observer: Rx.Observer<IArticle[]>) => {
        db.collection("articles")
            .find({ title: { $regex: `\\b${title}\\b`, $options: 'i' } })
            .toArray((err, result) => {
                if (err) { observer.onError(err); }
                observer.onNext(result);
                observer.onCompleted();
            });
    });
}
开发者ID:nuvolarit,项目名称:ts-demo,代码行数:31,代码来源:db.rx.ts

示例6: initialize

export async function initialize() {

    initializeLogger();
    const config = loadConfig()!;

    info( `Attempting to connect to mongodb...` );

    if ( !config.database )
        throw new Error( 'No database object defined in the config file' );

    const mongoServer = new MongoServer( config.database.host, config.database.port, { servername: config.database.name } );
    const mongoDB = new Db( config.database.name, mongoServer, { w: 1 } );
    const db = await mongoDB.open();

    info( `Successfully connected to '${config.database.name}' at ${config.database.host}:${config.database.port}` );
    info( `Starting up HTTP servers...` );

    // Create each of your servers here
    const promises: Array<Promise<any>> = [];

    await prepare( db, config );
    const clients = await discoverClients( config );

    const servers: Server[] = [];

    // First create the servers
    for ( const client of clients ) {
        if ( typeof client.server !== 'string' )
            servers.push( new Server( client.server, client.path ) );
    }

    // Now go through the add on clients and add the controllers
    // to any existing servers defined in the client
    for ( const client of clients ) {
        let server: Server | undefined;
        let clientServer = client.server;

        if ( typeof clientServer === 'string' )
            server = servers.find( s => s.server.host === clientServer );
        else
            server = servers.find( s => s.server.host === ( clientServer as IServer ).host );

        if ( !server ) {
            error( `Could not find an existing server with the name ${client.server}` );
            process.exit();
        }

        server!.parseClient( client );
    }

    for ( const server of servers )
        promises.push( server.initialize( db ) );

    // Load each of the servers
    await Promise.all( promises );

    info( `Server instances loaded...` );

    // Create the console manager
    if ( !args.runningTests )
        new ConsoleManager().initialize();
}
开发者ID:Webinate,项目名称:modepress,代码行数:62,代码来源:startup.ts

示例7: Server

// Mongo
import {Server} from "mongodb";
import {Db} from "mongodb";


var server = new Server("localhost", 27017, {auto_reconnect: true});
var db = new Db("chronicledb", server, {w: 1});
db.open(null);

export = db;
开发者ID:CorayThan,项目名称:legends-of-chronicle,代码行数:10,代码来源:db.ts

示例8: ouvrirConnection

 private ouvrirConnection() {
     this._db.open(function () { });
     this.ecrireLog("Connection base");
 }
开发者ID:lynxBZH,项目名称:expressjsExemple,代码行数:4,代码来源:appprincipal.ts

示例9: function

 open: function (callback) {
     db.open(callback);
 }
开发者ID:acrobat888,项目名称:NodeJS,代码行数:3,代码来源:db.ts


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