Reputation: 6904
I am using MongoDB with Mongoose.
I was wondering, if it is bad practice to use MongoDB IDs outside of MongoDB context. Since a lot of my objects need an ID to be identified, I was wondering if I just could use the IDs MongoDB gives them anyway or is that bad practice?
Best regards
Upvotes: 0
Views: 132
Reputation: 426
What I understand from your question is that if have a document from Mongodb that becomes an object in your application. To identify this object across the application, you want to use this _id so that changes to this object can be tracked easily. If this is the case, you should be using it happily. Because the ObjectId's of Mongodb are unique. Infact, I do use this _id in my android application. example code here
studentUniqueId.setText(dataModelItem.get_Id());
where studentUniqueId is a hidden field in my android application.
Upvotes: 1