本文整理匯總了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 });
}