C#mongodb driver 2.0-如何在批量操作中进行upsert? [英] C# mongodb driver 2.0 - How to upsert in a bulk operation?

查看:251
本文介绍了C#mongodb driver 2.0-如何在批量操作中进行upsert?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从1.9迁移到2.2,并阅读文档我很惊讶地发现,由于操作不允许使用选项,因此在批量操作期间再也无法进行升级.

I migrated from 1.9 to 2.2 and reading the documentation I was surprised to discover that is not possible to upsert during a bulk operation anymore, since operations don't allow options.

bulkOps.Add(new UpdateOneModel<BsonDocument>(filter, update));
collection.BulkWrite(bulkOps);

应该是

options.isUpsert = true;
bulkOps.Add(new UpdateOneModel<BsonDocument>(filter, update, options));
collection.BulkWrite(bulkOps);

这项工作是否正在进行中,是否有意进行,或者我缺少什么?谢谢.

Is this work in progress, intended, or I'm missing something? Thank you.

推荐答案

设置UpdateOneModelIsUpsert 属性设置为true,以将更新转换为upsert.

Set the IsUpsert property of the UpdateOneModel to true to turn the update into an upsert.

var upsertOne = new UpdateOneModel<BsonDocument>(filter, update) { IsUpsert = true };
bulkOps.Add(upsertOne);
collection.BulkWrite(bulkOps);

这篇关于C#mongodb driver 2.0-如何在批量操作中进行upsert?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆