Setting up mongo client to decode document result into bson.M (instead of the default bson.D) for empty interface

34 views
Skip to first unread message

Vimal Patel

unread,
Jan 17, 2020, 2:40:45 PM1/17/20
to mongodb-go-driver
I have a use case that requires me to decode document(s) result retrieved from calls to MongoDB via the Go Mongo driver into an empty/generic interface. The Mongo client by default returns the decoded result as a bson.D; however I need it to be returned as a bson.M so that I can output the decoded contents into our desired JSON structure. I have attempted various solutions including one provided in the comments for https://jira.mongodb.org/browse/GODRIVER-988 that involves setting the Mongo client registry to return bson.M instead of bson.D without success. I have attached small go program with instructions included as commented out lines towards the top of the program for you to reproduce this issue. My guess is that I am not setting the registry for the mongo client correctly, hence I am not getting the desired result.
demo.zip
Reply all
Reply to author
Forward
0 new messages