Hello World,
I’m currently updating a golang library that’s used in all our micro services that incorporates all the database objects and operations we allow them to use. Within every function that makes a call to the database there is a simple line collection := client.Database("").Collection("")
which obviously declares the collection being used. Now, below I have the struct returned by Collection()
-
type Collection struct {
client *Client
db *Database
name string
readConcern *readconcern.ReadConcern
writeConcern *writeconcern.WriteConcern
readPreference *readpref.ReadPref
readSelector description.ServerSelector
writeSelector description.ServerSelector
registry *bsoncodec.Registry
}
I have not dug into the methods associated with Collection
, but am I able to globally define collections so multiple functions can use it or should I keep the code the way it is? Keeping in mind the Collection()
function will find the lowest latency node for both reading and writing. Also, if you can, is there any decreased performance due to field writes locking the object?
Thanks,
Samuel