0

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
  • 1
    NO WAY! it will not append Commented Jul 27, 2015 at 15:03

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

by 'must' do you mean its necessary ? because right now I use a completely different format and it's working fine.
@GrishaGevorkyan can you provide me an example?
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.