本文整理汇总了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;
}
示例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
);
}
示例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);
});
}
});
示例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'));
示例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'));
示例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))
})
})
示例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))
})
})