Getting an error with docstore driver to communicate with mongoDB(Azure cosmos DB)

ERROR: "no field matching “_id” with utterance

I am using docstore package for mongodb connection. Code details are as follows,

// Open Collection:
//Using Azure Cosmos DB API , mongodocstore.OpenCollection constructor can open a Cosmos DB collection

client, err := c.newClient(ctx, true)
if err != nil {
	log.Error("error connecting to mongodb cluster", zap.Error(err))
	return nil, err
}

database := client.Database(c.dbName)
collection := database.Collection(c.collName)

return mongodocstore.OpenCollection(collection, "", nil)

// Query

i := s.collection.Query().Where("User", "=", user).Get(ctx)
defer i.Stop()

var results []*services.Utterance

for {
	var native utterance
	err := i.Next(ctx, &native) //getting above error at this line
	if err == io.EOF {
		break
	} else if err != nil {
		fmt.Println("err here: ")
		return nil, err
	}

	u := native.ToProto() //format output
	results = append(results, u)
}

return results, nil

// Go struct to map with mongodb document

type utterance struct {
ID primitive.ObjectID bson:"_id,omitempty"
User string bson:"User,omitempty"
Locale string bson:"Locale,omitempty"
Text string bson:"Text,omitempty"
Source string bson:"Source,omitempty"
Timestamp time.Time bson:"Timestamp,omitempty"
DocstoreRevision interface{}
}

What tag format should get used with Doctore? bson or docstore itself?

Tried using docstore annotations itself for golang struct as:

type utterance struct {
ID primitive.ObjectID docstore:"_id,omitempty"
User string docstore:"user,omitempty"
Locale string docstore:"Locale,omitempty"
Text string docstore:"Text,omitempty"
Source string docstore:"Source,omitempty"
Timestamp time.Time docstore:"Timestamp,omitempty"
DocstoreRevision interface{}
}

Error:
cannot set type primitive.ObjectID to ObjectID(“60d5e08639864e948a8851a5”)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.