I have read through MongoDB manual but still couldn't find what I need. Is it only 24 alphabet letters and 0123456789 are involved into autogenerated objectId or "id", Is there a chance that it will generate something like "jkfdfak-123kjsd?" and which exactly symbols are not used.
1 Answer
By default, ObjectId is a 12-byte BSON type, constructed using this data:
4-byte value representing the seconds since the Unix epoch
3-byte machine identifier
2-byte process id
3-byte counter, starting with a random value.
And the string representation is in hexadecimal.
If you want create your own ObjectId you must provide unique hexadecimal (0[xX][0-9a-fA-F]+) string.
3 Comments
Grisha Gevorkyan
by 'must' do you mean its necessary ? because right now I use a completely different format and it's working fine.
Jordi Martín
@GrishaGevorkyan can you provide me an example?
Grisha Gevorkyan
I have 2 objects from User collection with their userId. I create a Follow object in "Follows" collection, where objectId is 'user1Id-user2Id' which enables me to find follow object without queries just by objectId