當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mongodb.MongoClient類代碼示例

本文整理匯總了TypeScript中mongodb.MongoClient的典型用法代碼示例。如果您正苦於以下問題:TypeScript MongoClient類的具體用法?TypeScript MongoClient怎麽用?TypeScript MongoClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了MongoClient類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Promise

 var p1 = new Promise(function(resolve, reject){
   mongodb.MongoClient.connect(url, (err, db) => {
     if (!err) {
       DB = db;
       resolve(DB);
     }
     else {
       reject(err);
     }
   });
 });
開發者ID:bernardius,項目名稱:expressts,代碼行數:11,代碼來源:mongo-utils.ts

示例2: connect

 public async connect() {
     const options = mongodbUri.parse(config.MONGODB_URI);
     const uri = mongodbUri.format(options);
     const connection = await MongoClient.connect(uri, {
         useNewUrlParser: true,
     });
     this.database = connection.db(options.database);
     // tslint:disable-next-line
     console.log("Connected to DB...");
     return this.database;
 }
開發者ID:vnenkpet,項目名稱:japanese,代碼行數:11,代碼來源:db.ts

示例3: addTweets

    addTweets(tweets){
        MongoClient.connect(url, tweets, function (err, db) {
            assert.equal(null, err);
            console.log("Connected correctly to server.");
            assert.equal(null, err);
            this.insertDocuments(db, tweets, function () {
               db.close();
            });

        });
    }
開發者ID:bmtwebdevs,項目名稱:tweetchildofmine,代碼行數:11,代碼來源:repository.ts

示例4: connect

function connect(callback: (err, db) => void) {
    var url = 'mongodb://'
        + (process.env.OPENSHIFT_MONGODB_DB_USERNAME != null
        ? process.env.OPENSHIFT_MONGODB_DB_USERNAME + ':'
        + process.env.OPENSHIFT_MONGODB_DB_PASSWORD + '@'
        : '')
        + (process.env.OPENSHIFT_MONGODB_DB_HOST || '127.0.0.1') + ':'
        + (process.env.OPENSHIFT_MONGODB_DB_PORT || '27017') + '/'
        + 'minesweeper';
    MongoClient.connect(url, callback);
}
開發者ID:progre,項目名稱:minesweeper,代碼行數:11,代碼來源:database.ts

示例5: createCard

    createCard(card: Card, callback: (c: Card) => any) {
        this._client.connect(DaoConstants.CONNECTION_URL, (err:any, db:Db) => {
            db.collection('cards').insertOne(card, (err: MongoError, result: InsertOneWriteOpResult) => {
                card._id = result.insertedId.toString();

                db.close();

                callback(card);
            });
        });
    }
開發者ID:biwin,項目名稱:KandoeGroepJWebAndBackend,代碼行數:11,代碼來源:themeDao.ts

示例6: createTheme

    createTheme(t: Theme, callback: (theme: Theme) => any) {
        this._client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
            db.collection('themes').insertOne(t, (err: MongoError, result: InsertOneWriteOpResult) => {
                t._id = result.insertedId.toString();

                db.close();

                callback(t);
            });
        });
    }
開發者ID:biwin,項目名稱:KandoeGroepJWebAndBackend,代碼行數:11,代碼來源:themeDao.ts

示例7: addSubThemeToTheme

    addSubThemeToTheme(parentThemeId: string, childId: string, callback:(b: boolean) => any) {
        this._client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
            db.collection('themes').updateOne({'_id': new ObjectID(parentThemeId)}, {
                $push: {'_subThemes': childId}
            }, (err:MongoError, result) => {
                db.close();

                callback(result.modifiedCount == 1);
            });
        });
    }
開發者ID:biwin,項目名稱:KandoeGroepJWebAndBackend,代碼行數:11,代碼來源:themeDao.ts

示例8: removeAllUsersFromOrganisationById

    removeAllUsersFromOrganisationById(organisationId: string, callback: (removed: boolean) => any) {
        this.client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
            db.collection('users').updateMany({'_organisatorOf': {'$in': [organisationId]}}, {$pull: {'_organisatorOf': organisationId}}, (error: MongoError, result: UpdateWriteOpResult) => {
                db.collection('users').updateMany({'_memberOf': {'$in': [organisationId]}}, {$pull: {'_memberOf': organisationId}}, (error2: MongoError, result2: UpdateWriteOpResult) => {
                    db.close();

                    callback(result.modifiedCount == result.matchedCount && result2.modifiedCount == result2.matchedCount);
                });
            });
        });
    }
開發者ID:biwin,項目名稱:KandoeGroepJWebAndBackend,代碼行數:11,代碼來源:userDao.ts

示例9: getAllOrganisationIdsOfUserById

    getAllOrganisationIdsOfUserById(userId: string, callback: (organisationIds: string[]) => any) {
        this._client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
            db.collection('organisations').find({'$or': [{'_organisatorIds': {'$in': [userId]}}, {'_memberIds': {'$in': [userId]}}]}).project({'_id': 1}).toArray((err: MongoError, docs: Organisation[]) => {
                var ids: string[] = docs.map( o => o._id.toString());

                db.close();

                callback(ids);
            });
        });
    }
開發者ID:biwin,項目名稱:KandoeGroepJWebAndBackend,代碼行數:11,代碼來源:organisationDao.ts

示例10: connect

 public connect(): Observable<Db> {
     var observable: Observable<Db> = Observable.fromPromise<Db>(this.mongoClient.connect(this.url));
     observable.subscribe(
         (db: Db) => {
             this.db = db;
             this.userCollection = db.collection("users");
             this.historyCollection = db.collection("history");
         }
     );
     return observable;
 }
開發者ID:Kattoor,項目名稱:Uninova,代碼行數:11,代碼來源:userManager-old.ts


注:本文中的mongodb.MongoClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。