Answer the question
In order to leave comments, you need to log in
How to remove an element from an array in MongoDB?
Remove element from expenses array
{"_id":{"$oid":"12"},
"chatID":{"$numberInt":"12"},
"expenses":[
{"category":"food","amount":{"$numberDouble":"12.0"}},
{"category":"food","amount":{"$numberDouble":"14.0"}}],
"income":[]}
update := bson.M{"$pull": bson.M{"expenses": bson.D{{"category", "food"}, {"amount", 12}}}}
c.Coll.UpdateOne(context.TODO(), bson.M{"chatID": chatID}, update)
{"_id":{"$oid":"12"},
"chatID":{"$numberInt":"12"},
"expenses":[
{"category":"food","amount":{"$numberDouble":"14.0"}}],
"income":[]}
Answer the question
In order to leave comments, you need to log in
https://github.com/tidwall/sjson
well, to the heap https://github.com/tidwall/gjson
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question