jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
287 stars 65 forks source link

Upsert dataframe using subject$insert() #210

Closed eduardokapp closed 4 years ago

eduardokapp commented 4 years ago

Is it possible to use subject$insert() but in an "upsert" fashion?

I have a need to constantly update document entries that look like: '{"id": "some_id", "date": "some_date", "value": "some_value"}

These documents are stored in a data.frame R object, and they may have different IDs (for example) and different values. I could just use subject$insert() but then I would ignore duplicates. I think it would also be possible to use subject$update, however if I go this way I would need to do one query at a time, wouldn't I?

eduardokapp commented 4 years ago

The only solution I found was to query all the values I know will be duplicated, delete them and then insert the dataframe you want to upsert.