Reputation: 3
I am using mongodb with php. I want to know when we create a new mongo id using new MongoId() How does it consult to the database for ensuring unique id, I mean is it a write operation or read operation.
Upvotes: 0
Views: 52
Reputation: 42028
Generation of the ObjectId happens locally, it's not a database operation. 4 values are used to generate the ObjectId:
::Time.new.to_i
Digest::MD5.digest(Socket.gethostname).unpack("N")[0]
Process.pid % 0xFFFF
@counter = (@counter + 1) % 0xFFFFFF
You can find the full code here.
Upvotes: 1