本文整理汇总了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))
})
})
示例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));
}
示例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))
})
})
示例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))
})
})
示例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);
}
);
});
}
示例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))
})
})
示例7:
return Observable.create<User[]>((observer) =>
this.userCollection.find({}).forEach(
document =>
users.push(document),
() =>
observer.onNext(users)
)
示例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))
})
})
示例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
);
}
示例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);
}