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?