globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

feature to set object ID for all the objects within an array (like mo… #200

Closed Vish511 closed 6 years ago

Vish511 commented 6 years ago

…ngoose js).. please assist further on where to update example usage for this with documentation...thanks in advance!

domodwyer commented 6 years ago

Hi @Vish511

What is this for exactly? A description will help us understand the use case.

Dom

Vish511 commented 6 years ago

Hi @domodwyer , This is a feature to add Mongo Object ID to sub documents as well(for the objects in an array), basically to make each element be uniquely referenced just as the top level document has an _id. I have worked on the mean stack extensively and this feature is part of monjoose js which is an ODM for mongodb. This feature solved many problems with node js. I couldn't find it in go. { "_id" : ObjectId("5b34ec758e4e64019b3a2afb"), "orderName" : "order_1", "orderedItems" : [ { "itemName" : "item1", "itemQty" : 3.0, "_id" : ObjectId("5b34ecb48e4e64019b3a2afc") }, { "itemName" : "item2", "itemQty" : 6.0, "_id" : ObjectId("5b34ecb48e4e64019b3a2afd") } ] } Object ID within an array is helpful to identify the element uniquely. Otherwise for every array we have to maintain a separate collection for counters and that causes too much complexity. Mongoose js had this feature. Please give me your valuable feedback. Cheers!

domodwyer commented 6 years ago

Hi @Vish511

While the PR really is appreciated, I don't really see how this is the responsibility of the driver? Can this not be added to the application (by explicitly setting an ID before passing it to mgo)?

Dom

Vish511 commented 6 years ago

Hi @domodwyer , Thanks for your feedback. It can certainly be done at the application level. I just thought of making the driver support it as in mongoose js thinking it could be useful in solving many real world problems and would be generic. Anyways thanks once again and cheers!

domodwyer commented 6 years ago

Hi @Vish511

Thanks for the PR and your understanding! We take a more conservative view of what belongs in the driver than some others (like mongoose) to try and keep the maintenance of mgo lower.

Dom