ruby on rails - How to generate string value for _id field in mongodb collection? -


i want generate id of newly created object string instead of bson::objectid('59afe79b92caf8948b000005').

i using mongoid of version mongoid (4.0.2) .

is there idgeneration of page https://docs.meteor.com/api/collections.html .

i want create id random string(swpabpucounbrjzoh) work our meteor application.

any suggestion helpful me.

thanks,

if generate @ end , assign _id field in insert query, mongo shall accept _id. if don't specify field name _id mongodb intelligently creates _id field generated algorithm can used sorting purpose in future.

here information how object id generated mongodb. click here

you can self generate _id around 17 character (depends how long need it). before inserting make sure not exists. mongodb indexes keys identified field _id. can click here know more how generate desired key. take hints , develop own code.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -