S
S
s_pyanov2019-08-14 03:42:50
MongoDB
s_pyanov, 2019-08-14 03:42:50

How in mgo.v2 to select data by one field but with different given values?

Good day to all.
There is a base with documents of goods. Products are from different manufacturers.
From the frontend there is a request for a selection of goods (the Manufacturer field), for 2 manufacturers: HP, Xerox.
It is necessary to select documents that meet the condition from the database.
Displaying all products of one manufacturer is not a problem:

query := bson.M{"manufacture": "hp"}
  var list []Tovar
  err = c.Find(query).All(&list)

But here's how to set the filter by two values ​​of the "manufacture" field?
Tried something like:
query := bson.M{
    "manufacture": [{"hp"},{"Xerox"}]}

But that doesn't work by itself.
I read the documentation on the mongi site, I found an example:
coll.Find(
  context.Background(),
  bson.D{{"status", bson.D{{"$in", bson.A{"A", "D"}}}}})

But go swears that bson.A he does not understand!
Can't figure out what the syntax should be.
Maybe I'm not building the query correctly at all? Kindly tell me how to do it right)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2019-08-14
@VladimirAndreev

query := bson.M{
"manufacture": ["hp","Xerox"]}
Doesn't work either?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question