SoftInstigate / restheart

Open Source Low-code API development framework Featuring ready-to-go Security and MongoDB API
http://softinstigate.github.io/restheart/
GNU Affero General Public License v3.0
792 stars 170 forks source link

bulk post with writeMode=update does not replace the matching documents but just updates the passed properties #499

Closed ujibang closed 2 months ago

ujibang commented 5 months ago

Describe the bug

The mongodb rest API bulk post, i.e. does not replace the whole matching documents. Instead it just updates the passed properties of matching documents

Create 2 docs

POST /coll?wm=upsert

[  { "_id": 1, "a": 1 },  { "_id": 2, "a": 2 } ]

Now execute the bulk update:

POST /coll?wm=update

[  { "_id": 1, "b": 1 },  { "_id": 2, "b": 2 } ]

The resulting documents will have both a and b properties. They should only have the b property.

This is due to DbUtils.bulkWriteDocuments() uses UpdateOneModel.

It should use ReplaceOneModel instead.