A
A
Artem Prokhorov2021-12-27 22:29:06
MongoDB
Artem Prokhorov, 2021-12-27 22:29:06

How to remove go.mongodb.org/mongo-driver/bson/primitive.E composite literal uses unkeyed fields?

users.UpdateOne(ctx, bson.M{"username": username}, bson.D{
    {"$set", bson.D{{"status", true}}},
  })

Highlights it{"$set", bson.D{{"status", true}}},

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Prokhorov, 2021-12-28
@kotcich

Here is the solution:

_, err := users.UpdateOne(ctx, bson.M{"username": "kotcich"}, bson.D{
    {Key: "$set", Value: bson.D{{Key: "status", Value: true}}},
  })

As far as I understand the essence of the error: it is better to always explicitly indicate what is the key and what is the value, so that new versions of the database, with a possible rearrangement of the key / value order, still work correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question