当前位置: 首页>>代码示例>>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;未经允许,请勿转载。