English 中文(简体)
将Batch Upsert添加到MongoDB。
原标题:Adding Batch Upsert to MongoDB.
  • 时间:2012-01-14 01:57:26
  •  标签:
  • mongodb

它认为莫奥果非行不支持批发。 这是否正确?

如果没有,那么,你将如何与现有的、效率最强的预报器一道添加警示吗? bat是否甚至对mongo db有利?

问题回答

For C# MongoDB.Driver I use next:

        var writeModels = new List<WriteModel<T>>();
        foreach (var entity in list)
        {
            var id = entity.Id;
            if (id == null)
            {
                writeModels.Add(new InsertOneModel<T>(entity));
            }
            else
            {
                var filter = new ExpressionFilterDefinition<T>(x => x.Id == id);
                var replaceModel = new ReplaceOneModel<T>(filter, entity);
                writeModels.Add(replaceModel);
            }
        }
        await getCollection().BulkWriteAsync(writeModels);




相关问题
Access DB Ref MongoDB

Whats the best way to access/query a DB Ref: UPDATE: users: name, groupref : {$ref:"groups",$id:"ObjectId ..." } } groups: name, topic, country,...,.. Assumption is that user belongs to only one ...

MongoDB nested sets

What re the best practices to store nested sets (like trees of comments) in MongoDB? I mean, every comment can have a parent comment and children-comments (answers). Storing them like this: { ...

MongoMapper and migrations

I m building a Rails application using MongoDB as the back-end and MongoMapper as the ORM tool. Suppose in version 1, I define the following model: class SomeModel include MongoMapper::Document ...

MongoDB takes long for indexing

I have the following setup: Mac Pro with 2 GB of RAM (yes, not that much) MongoDB 1.1.3 64-bit 8 million entries in a single collection index for one field (integer) wanted Calling .ensureIndex(...) ...

Storing and accessing large amounts of data

My application creates pieces of data that, in xml, would look like this: <resource url="someurl"> <term> <name>somename</name> <frequency>somenumber</...

热门标签