Answer the question
In order to leave comments, you need to log in
How to work with a received document from MongoDB using Go?
I get the document using FindOne()
This is how it looks in go:
map[
_id:ObjectID("12")
chatID:12
expenses:[
map[amount:12 category:food]
map[ amount:14 category:food]]
income:[]]
{"_id":{"$oid":"12"},
"chatID":{"$numberInt":"12"},
"expenses":[
{"category":"food","amount":{"$numberDouble":"12.0"}},
{"category":"food","amount":{"$numberDouble":"14.0"}}],
"income":[]}
Answer the question
In order to leave comments, you need to log in
type Expense struct {
Category string `bson:"category"`
Amount float `bson:""amount"`
}
type MyDoc struct {
ID primitive.ObjectID `bson:"_id, omitempty"`
ChatID int `bson:"chatID"`
Expenses []Expense `bson:"expense"`
Income []int(тип какой хотите) `bson:"income"`
myDoc = MyDoc{}
err = mongo.FindOne(context.TODO(), {}).Decode(&myDoc)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question