jeroen / mongolite

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

Create new ObjectID from scratch #151

Open AndreGuerra123 opened 6 years ago

AndreGuerra123 commented 6 years ago

Hello, How can someone create a unique ObjectID from scratch (i.e. I don't have a hex string)? In the rmongodb package would be something like this: oid <- mongo.oid.create() Thank you for your help, Andre

AndreGuerra123 commented 6 years ago

OBID <- function(){ ei <- as.hexmode(as.integer(Sys.time())) # 4-byte mi <- as.hexmode(6666666) #3-byte (I don't really care about the machine suplying this) pi <- as.hexmode(Sys.getpid()) # 2-byte ci <- as.hexmode(sample(1048576:16777215,1)) # 3-byte return(paste0(ei,mi,pi,ci)) }

atheriel commented 6 years ago

I don't think there's a way to do this at present. But I'm curious -- what's the use case for this?

AndreGuerra123 commented 6 years ago

A use case: brand new insertion does not return id to the client for instance, so the id must be created and forked.

AndreGuerra123 commented 6 years ago

The code above has been working successfully. If there is a way to find the machine ip or mac and replace the bytes would improve but for my use case it's ok.

atheriel commented 6 years ago

It looks like this has been discussed before in #80 and #87. Do you know what happens if you insert records containing the result of rmongodb::mongo.oid.create()? Do they get correctly interpreted as OIDs?

AndreGuerra123 commented 5 years ago

why should install a different (deprecated) driver?