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


TypeScript Collection.find方法代碼示例

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


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

示例1: resolve

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

示例2: User

 observer => {
     Observable.fromPromise<CursorResult>(this.userCollection.find({registeredNumber: registeredNumber}).limit(1).next()).map(
         doc => {
             return doc == null ? null : new User(doc.username, "nice try ;)", doc.day, doc.registeredNumber, doc.hasAquaSmart, doc.buildings, doc._id);
         }
     ).subscribe((user: User) => observer.onNext(user));
 }
開發者ID:Kattoor,項目名稱:Uninova,代碼行數:7,代碼來源:userManager.ts

示例3: 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

示例4: 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

示例5: findAll

    public async findAll(): Promise<ScheduledEvent[]> {
        const cursor = await this.collection.find();

        return new Promise<ScheduledEvent[]>(resolve => {
            const schedule = [];

            cursor.forEach(
                doc => {
                    const event = this.serializer.deserialize(
                        doc.event,
                        this.eventClassMap.getTypeByClassName(doc.eventType)
                    );

                    schedule.push({
                        event: event,
                        timestamp: doc.timestamp,
                        token: doc.token
                    });
                },
                () => {
                    cursor.close();
                    resolve(schedule);
                }
            );
        });
    }
開發者ID:martyn82,項目名稱:aphajs,代碼行數:26,代碼來源:MongoDbScheduleStorage.ts

示例6: resolve

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

示例7:

 return Observable.create<User[]>((observer) =>
     this.userCollection.find({}).forEach(
         document =>
             users.push(document),
         () =>
             observer.onNext(users)
     )
開發者ID:Kattoor,項目名稱:Uninova,代碼行數:7,代碼來源:userManager-old.ts

示例8: resolve

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

示例9: 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

示例10:

 observer => {
     var username: string = TokenManager.getField(token, "username");
     if (TokenManager.validate(token)) {
         Observable.fromPromise<CursorResult>(this.userCollection.find({username: username}).limit(1).next()).map(doc => doc.day).subscribe(
             currentDay => {
                 this.saveAsHistoryFor(username, currentDay, JSON.parse(buildings)).subscribe( // save history
                     () => {
                         this.updateUserBuildings(token, JSON.parse(buildings)).subscribe( // save user
                             () => {
                                  // change bassins and mortality and such
                                 var parsedBuildings: Building[] = JSON.parse(buildings);
                                 if (parsedBuildings != null && parsedBuildings.length > 0) {
                                     for (var building of parsedBuildings) {
                                         if (building.bassins != null && building.bassins.length > 0) {
                                             for (var bassin of building.bassins)
                                                 bassin.amountOfFishes -= this.calculateFatalities(bassin);
                                         }
                                     }
                                 }
                                 console.log("oh hello is it me you're looking for")
                                 this.incrDayForUser(username, +currentDay).subscribe(() => observer.onNext(parsedBuildings));
                             }
                         );
                     }
                 );
             }
         );
     } else
         observer.onNext(null);
 }
開發者ID:Kattoor,項目名稱:Uninova,代碼行數:30,代碼來源:userManager.ts


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