Seeing as this value is unique and present for all users in a mongo database, are there any particular caveats to using this as a user identifier in a web application?
Particular issues I may be considering include if in the future the users need to be transferred.
Is it ok to use Mongo's “Object ID” as its unique identifier? Yes, it is intended for this purpose. Making unique IDs can be a pain in sharded environments, so MongoDB does this for you.
No matter if it's MongoDb, SQL or any other id. Id is the key to data. If this key is only thing you need to view content that you should not - that's an issue.
Overview. By default, the MongoDB Java driver generates IDs of the type ObjectId. Sometimes, we may want to use another type of data as the unique identifier of an object, such as a UUID. However, the MongoDB Java driver can't generate UUIDs automatically.
All documents in MongoDB must have a populated _id field. If a document hasn't been assigned an _id value, MongoDB will automatically generate one.
... are there any particular caveats to using this as a user identifier in a web application?
A few that I've seen:
Particular issues I may be considering include if in the future the users need to be transferred.
Transferred to where? Once you start storing user's data in MongoDB, the IDs are going to be the least of your problems transferring to another DB. All modern DBs can handle some form of String or Binary as the primary key ID, so your transfer should work just fine. But most of the complexity will have nothing to do with the ID.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With