[GODRIVER-615] undefined: TransformDocument Created: 26/Oct/18  Updated: 11/Sep/19  Resolved: 03/Dec/18

Status: Closed
Project: Go Driver
Component/s: BSON
Affects Version/s: 0.0.17
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Calvin Assignee: Kristofer Brandow (Inactive)
Resolution: Done Votes: 0
Labels: packages
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I've been getting this error when I try to build my application that imports 

"github.com/mongodb/mongo-go-driver/mongo"

 

command-line-arguments
./genepool.go:50:17: undefined: mongo.TransformDocument

**I have my GOPATH set up correctly to find the other mongo-go-driver packages and it builds if I remove the code that uses mongo.TransformDocument()

I originally saw this when I was trying to build my app in Docker. I couldn't reproduce it locally until I uninstalled and re-installed go-mongo-driver, then it started happening.

I'm thinking this is a bug that was introduced recently. Unfortunately I am not sure what version I was on before.

 



 Comments   
Comment by Kristofer Brandow (Inactive) [ 05/Nov/18 ]

Hi lobocv,

You should be able to use bson.D or bson.M. Use a bson.D or bson.M in the place where you have currently called bson.NewDocument.

--Kris

Comment by Calvin [ 26/Oct/18 ]

Bah, I realized that in the latest version TransformDocument was turned private.

If I have a structure that I want to convert to a document so that I can update it's value in the database, how do I do this? 

Currently I was doing this:

collection := db.Collection(MicrocosmCollection)
for _, m := range microcosms {
 if doc, err = mongo.TransformDocument(m); err != nil {
 log.Fatal(err)
 }
 if oid, err = objectid.FromHex(m.Id); err != nil {
 log.Fatal(err)
 }
 
 res, err = collection.UpdateOne(context.Background(),
 bson.NewDocument(bson.EC.ObjectID("_id", oid)),
 bson.NewDocument(bson.EC.SubDocument("$set", doc)),
 )

Generated at Thu Feb 08 08:34:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.