When I use Mongodb with Java, I want to generate Object id at clients. Before I insert a record, however, I have to query mongodb first to make sure that the id generated by
Object IDs are not like sequential ids you use in a RDMS. If they are properly generated according to the Object ID specification you will not need to worry about them being unique.
All you have to do is ensure you always create a new Object ID rather than reusing them.