本文整理汇总了TypeScript中mongodb.Collection.findOneAndReplace方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Collection.findOneAndReplace方法的具体用法?TypeScript Collection.findOneAndReplace怎么用?TypeScript Collection.findOneAndReplace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongodb.Collection
的用法示例。
在下文中一共展示了Collection.findOneAndReplace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
lr.on('line', function (line:string) {
// 'line' contains the current line without the trailing newline character.
let item = JSON.parse(line);
report.total++;
if (item.price === undefined) {
report.errors++;
report.errList[item.name] = 'no price';
process.stdout.write("x");
return;
}
process.stdout.write(".");
let cItem:MsCartItem = new MsCartItem(undefined,item.name[0],getFloat(item.price,undefined));
cItem.crawler = report.crawler;
cItem.shopname = source;
cItem.category = item.category[0] || defaultCat;
if (cItem.category && report.categories.indexOf(cItem.category) === -1) report.categories.push(cItem.category);
cItem.currency = 'EUR';
cItem.description = buildDesc(item);
let oprice:number = getFloat(item.oldPrice,undefined);
cItem.discount = (oprice)?+((oprice - cItem.price)/oprice).toFixed(2):undefined;
cItem.imgUrl = item.imgUrl[0];
cItem.link = (item.buyLink)? item.buyLink[0] : item.url;
cItem.BOPIS = (item.bopisLink)? item.bopisLink[0] : null;
cItem.outOfStock = false;
cItem.qty = 1;
cItem.sku = item.sku || getSku(cItem.link);
cItem.secondhand = false;
cItem.shippedPrice = getFloat(item.shippedPrice,' ');
cItem.shipCost = (cItem.shippedPrice>0)?cItem.shippedPrice-cItem.price:defaultShipCost;
cItem.refresh = report.mills;
if((report.skus[cItem.sku]===undefined)){
report.skus[cItem.sku] = 1;
collection.findOneAndReplace({"sku":cItem.sku,"shopname":cItem.shopname},cItem, { upsert : true }, function(err:any,result:any){
if (!err){
report.updates += (result.lastErrorObject.updatedExisting)?1:0;
report.inserts += (result.lastErrorObject.updatedExisting)?0:1;
}else
report.errors++;
});
}else{
report.duplicates++;
report.skus[cItem.sku]++;
}
});
示例2: upsert
public async upsert(id: string, projection: T): Promise<void> {
const document = projection.copy();
document["__id"] = id;
await this.collection.findOneAndReplace({__id: id}, document, {upsert: true});
}