Inserting key to documents where it doesn't exist and update it wherever it does

I recently started using mongolite. And I am having trouble reproducing some MongoDB queries in R.

I want to do something like this

update_training_month <- function(month){
  m <- mongo(collection = trained_model, db = database)
  m$update({'month': {"$exists" : FALSE}}, {"$set": {'month': month}})
}

So the month field doesn't exist and I want to update it.

Moreover, I want the month field to be a variable to be input by the user but I am unable to define a function like that because that throws an invalid JSON error.
I have referred to the documentation. But haven't found solutions to my queries.
Could someone please help me with this?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.