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


TypeScript mongodb.Collection類代碼示例

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


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

示例1: checkCollectionIndexes

  async checkCollectionIndexes(coll:Collection): Promise<any> {
    const indexes = this.getIndexes();
    if (indexes && indexes.length) {
      let currIndexes;
      try {
        currIndexes = await coll.indexes();
      } catch(e) {
        currIndexes = [];
      }
      for (let i of indexes) {
        const props = [ 'unique', 'sparse', 'min', 'max', 'expireAfterSeconds', 'key' ];

        let c_i = currIndexes.find(t => {
          return (typeof i.name === 'undefined' || i.name === t.name) && _.isEqual(_.pick(i, props), _.pick(t, props));
        });
        if (!c_i) {
          if (this.createIndexes) {
            logger.info(this.name, 'creating missing index', i);
            await coll.createIndex(i.key, _.omit(i, 'key'));
          } else {
            logger.warn(this.name, 'missing index', i);
          }
        }
      }
    }
    this[__indexesChecked] = true;
  }
開發者ID:vivocha,項目名稱:arrest,代碼行數:27,代碼來源:resource.ts

示例2: getDummyData

 public getDummyData(type: string): Observable<string> {
     var userCollection: Collection = this.db.collection("dummydata");
     return Observable.fromPromise<CursorResult>(userCollection.find({type: type}).limit(1).next()).map(
         doc =>
             doc == null ? null : doc.content
     );
 }
開發者ID:Kattoor,項目名稱:Uninova,代碼行數:7,代碼來源:userManager-old.ts

示例3:

 Observable.fromPromise<number>(this.historyCollection.count({username: username})).subscribe(count => {
     if (count == 0) {
         Observable.fromPromise<InsertOneWriteOpResult>(this.historyCollection.insertOne({username: username, days: [dayInfo]})).subscribe(() => {
             console.log("Finished creating");
             observer.onNext("sup")
         });
     } else {
         Observable.fromPromise<any>(this.historyCollection.findOneAndUpdate({username: username}, { $push: {days: dayInfo}})).subscribe(() => {
             console.log("Finished inserting");
             observer.onNext(true);
         });
     }
 });
開發者ID:Kattoor,項目名稱:Uninova,代碼行數:13,代碼來源:userManager.ts

示例4:

 Promise.all(updates.map(update => {
     if (update.method === 'add') {
         return col.insertOne(update.racer);
     } else {
         return col.deleteOne({id: update.id});
     }
 })).then(() => process.send('update'));
開發者ID:Tiedye,項目名稱:RazzieTest,代碼行數:7,代碼來源:stress-test-racer.ts

示例5:

 Promise.all(updates.map(update => {
     if (update.method === 'add') {
         return col.findOneAndUpdate({"id":update.team}, {"$push":{"racers":update.racer}});
     } else {
         return col.findOneAndUpdate({"racer.id":update.id}, {"$pull":{"racers":{"id":update.id}}});
     }
 })).then(() => process.send('update'));
開發者ID:Tiedye,項目名稱:RazzieTest,代碼行數:7,代碼來源:stress-test-team.ts

示例6: resolve

 return new Promise<Attendee>((resolve, reject) => {
   this._collection.find({ attendeeid: attendeeid }).limit(1).toArray().then((attendees: Attendee[]) => {
     resolve(attendees.length > 0 ? attendees[0] : null)
   }).catch((err) => {
     reject(new Error('Error when finding attendee: ' + err.message))
   })
 })
開發者ID:TechNottingham,項目名稱:Hack24-API,代碼行數:7,代碼來源:attendees.ts

示例7: resolve

 return new Promise<Hack>((resolve, reject) => {
   this._collection.find({ name: name }).limit(1).toArray().then((hacks: Hack[]) => {
     resolve(hacks.length > 0 ? hacks[0] : null)
   }).catch((err) => {
     reject(new Error('Error when finding hack: ' + err.message))
   })
 })
開發者ID:TechNottingham,項目名稱:Hack24-API,代碼行數:7,代碼來源:hacks.ts


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