本文整理汇总了TypeScript中mongodb.Collection.findOneAndUpdate方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Collection.findOneAndUpdate方法的具体用法?TypeScript Collection.findOneAndUpdate怎么用?TypeScript Collection.findOneAndUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongodb.Collection
的用法示例。
在下文中一共展示了Collection.findOneAndUpdate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
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'));
示例2: upsert
public async upsert(name: string, version: number): Promise<void> {
await this.collection.findOneAndUpdate(
{name: name},
{name: name, version: version},
{upsert: true}
);
}
示例3: gen_item
return new Promise<boolean>((resolve, reject) => {
var filter = { name },
update = gen_item(name, value, ttl),
option = { upsert: true };
coll.findOneAndUpdate(filter, update, option)
.then(() => resolve(true))
.catch(reject);
});
示例4:
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);
});
}
});
示例5: update
public async update(
sagaClass: string,
id: string,
associationValues: AssociationValueDescriptor,
data: string
): Promise<void> {
await this.collection.findOneAndUpdate({id: id}, {
id: id,
sagaClass: sagaClass,
payload: data,
associationValues: associationValues
}, {upsert: true});
}
示例6: save
export function save(coll: Collection, message: Message): Promise<FindAndModifyWriteOpResultObject> {
let upsert = true;
let signature = message.signature;
return coll.findOneAndUpdate({ signature }, message, { upsert });
}