C#mongodb驱动2.0 - 如何插入批量操作?
问题描述:
我从1.9迁移到2.2和reading the documentation我很惊讶地发现,在批量操作期间不可能再插入,因为操作不允许选项。C#mongodb驱动2.0 - 如何插入批量操作?
bulkOps.Add(new UpdateOneModel<BsonDocument>(filter, update));
collection.BulkWrite(bulkOps);
应该
options.isUpsert = true;
bulkOps.Add(new UpdateOneModel<BsonDocument>(filter, update, options));
collection.BulkWrite(bulkOps);
正在进行这项工作,计划或我失去了一些东西?谢谢。
答
将UpdateOneModel
的IsUpsert
属性设置为true以将更新转换为upsert。
var upsertOne = new UpdateOneModel<BsonDocument>(filter, update) { IsUpsert = true };
bulkOps.Add(upsertOne);
collection.BulkWrite(bulkOps);
这应该被添加到文档中。谢谢!! –
什么是bulkOps?我如何获得一个? –