Reputation: 1875
Hi I'm tyring to update collection in mongodb using mongolite
package, but I can't figure out why is my query failing(google was of no help).
I'm tring to run update command but I I get error saying that timestamp is invalid:
files$update(
query = "{\"FileId\" : \"F0FFFBDA14E1D49547C24CD5150\" }",
update = "{ \"$set\" : {\"Contract\" : \"1\"},
\"$currentDate\" : {\"Updated\" : { \"$type\" : \"timestamp\" } } }")
Error: Invalid input string timestamp, looking for 6
This is the object that I'm trying to udpate:
{ "_id" : ObjectId("59d3fc93ec2d602b7967f4a7"),
"Client" : "Someone",
"FileId" : "F0FFFBDA14E1D49547C24CD5150"
}
I pretty sure that my query is correct I was able to execute it in mongo
shell client.
Upvotes: 2
Views: 299
Reputation: 1875
Using mongolite's documetnation I found out how to add my own timestamp, which happens to be time now.
Basically instead of using $currentDate
operator I used $set
and with a littlebit of R code I figured out what value shoudl I set Updated
field to:
sub(
"NOW",
format(Sys.time(), "%Y-%m-%dT%H:%M:%SZ", 'EST'),
'"$set" : {"Updated" : "NOW"}'
)
See documentation for more details.
Upvotes: 1