Home > database >  Directing at the same time perform bulk insert and update the fields to insert or update
Directing at the same time perform bulk insert and update the fields to insert or update

Time:10-05

Want to pass the batch update by UpdateOptions set to TRUE plug in mass data into mongo, have A, B, C three fields,
Through A field, if no value into A, B, C, if A query has value is updated C field, want to pass the batch update way
UpdateOneModel Uom=new UpdateOneModel (queryDocument updateDocument, new UpdateOptions (). The upsert (true));
But it has a problem, B value cannot be assigned or can be updated,


Because large quantities of data processing, under the premise of considering performance sex does not consider the following handling
First query mongo to insert A value of the data, to tell other data updates,

Just contact mongo soon, I pray you big xian help to see if there are any does not affect the performance of the situation more better solution,

CodePudding user response:

List Requests=new ArrayList (a);

UpdateOneModel Uom=new UpdateOneModel (queryDocument updateDocument, new UpdateOptions (). The upsert (true));
Requests. The add (uom);
BulkWriteResult BulkWriteResult=coll. BulkWrite (requests);

Now with this batch processing data, but can't solve the problems above
  • Related