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