-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fix bulk post with writeMode=update does not replace the matching d…
…ocuments but just updates the passed properties #499
- Loading branch information
Showing
1 changed file
with
19 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,25 +20,12 @@ | |
*/ | ||
package org.restheart.mongodb.db; | ||
|
||
import com.mongodb.client.ClientSession; | ||
import com.mongodb.client.MongoCollection; | ||
import com.mongodb.client.model.BulkWriteOptions; | ||
import static com.mongodb.client.model.Filters.and; | ||
import static com.mongodb.client.model.Filters.eq; | ||
import static com.mongodb.client.model.Filters.exists; | ||
import com.mongodb.client.model.FindOneAndReplaceOptions; | ||
import com.mongodb.client.model.FindOneAndUpdateOptions; | ||
import com.mongodb.client.model.InsertOneModel; | ||
import com.mongodb.client.model.ReplaceOptions; | ||
import com.mongodb.client.model.ReturnDocument; | ||
import com.mongodb.client.model.UpdateOneModel; | ||
import com.mongodb.client.model.UpdateOptions; | ||
import com.mongodb.client.model.WriteModel; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.bson.BsonArray; | ||
import org.bson.BsonBoolean; | ||
import org.bson.BsonDateTime; | ||
|
@@ -51,11 +38,26 @@ | |
import org.bson.types.ObjectId; | ||
import org.restheart.exchange.ExchangeKeys.METHOD; | ||
import org.restheart.exchange.ExchangeKeys.WRITE_MODE; | ||
import org.restheart.utils.HttpStatus; | ||
import org.restheart.utils.BsonUtils; | ||
import org.restheart.utils.HttpStatus; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.mongodb.client.ClientSession; | ||
import com.mongodb.client.MongoCollection; | ||
import com.mongodb.client.model.BulkWriteOptions; | ||
import static com.mongodb.client.model.Filters.and; | ||
import static com.mongodb.client.model.Filters.eq; | ||
import static com.mongodb.client.model.Filters.exists; | ||
import com.mongodb.client.model.FindOneAndReplaceOptions; | ||
import com.mongodb.client.model.FindOneAndUpdateOptions; | ||
import com.mongodb.client.model.InsertOneModel; | ||
import com.mongodb.client.model.ReplaceOneModel; | ||
import com.mongodb.client.model.ReplaceOptions; | ||
import com.mongodb.client.model.ReturnDocument; | ||
import com.mongodb.client.model.UpdateOptions; | ||
import com.mongodb.client.model.WriteModel; | ||
|
||
/** | ||
* | ||
* @author Andrea Di Cesare {@literal <[email protected]>} | ||
|
@@ -423,8 +425,8 @@ static List<WriteModel<BsonDocument>> getBulkWriteModel( | |
} | ||
|
||
switch(writeMode) { | ||
case UPSERT -> updates.add(new UpdateOneModel<>(_filter, getUpdateDocument(document), new UpdateOptions().upsert(true))); | ||
case UPDATE -> updates.add(new UpdateOneModel<>(_filter, getUpdateDocument(document), new UpdateOptions().upsert(false))); | ||
case UPSERT -> updates.add(new ReplaceOneModel<>(_filter, document, new ReplaceOptions().upsert(true))); | ||
case UPDATE -> updates.add(new ReplaceOneModel<>(_filter, document, new ReplaceOptions().upsert(false))); | ||
case INSERT -> updates.add(new InsertOneModel<>(document)); | ||
} | ||
}); | ||
|