MongoDB best practices for choosing _id field type -


i'm write webapp based on node.js , mongodb. webapp have users stored in table users. question quite simple: since username unique, idea change _id field type objectid string contain username?

i think more convenient , somehow reduce number of requests needed perform several tasks. typically if use username _id, references user in other tables directly give me username , not objectid i'd need convert intelligible name before displaying it.

moreover having 2 different fields (objectid _id + username) require 2 indexes speed lookups either on ids or on usernames , require more space in database.

last, if understood correctly documentation, on sharded environment, mongodb able ensure uniqueness of _id field.

but, may miss things i'd realize (and regret) later.

can please shed light on this?

thanks!


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -