D
D
Dmitry Afonchenko2018-06-28 10:23:07
MongoDB
Dmitry Afonchenko, 2018-06-28 10:23:07

Why doesn't aggregation work in MGO?

Good afternoon, comrades. I recently started working with Go and the task was to pull some data out of mongi. I made such a simple pipeline for selecting by date:

fromDateS := time.Date(2017, time.July, 2, 0, 0, 0, 0, time.UTC)
toDateS := time.Date(2019, time.July, 2, 0, 0, 0, 0, time.UTC)

pipeline := []bson.M{
    bson.M{
      "$match": bson.M{
        "ReceivedTime": bson.M{
          "$gt": fromDateS,
          "$lt": toDateS,
        },
      },
    },
  }

pipe := collection.Pipe(pipeline)

var results []Record
err = collection.Find(pipe).All(&results)

For some reason, it pulls all records from the collection, although this query works correctly:
fromDateS := time.Date(2017, time.July, 2, 0, 0, 0, 0, time.UTC)
toDateS := time.Date(2019, time.July, 2, 0, 0, 0, 0, time.UTC)

var results []Record
err = collection.Find(bson.M{
  "ReceivedTime": bson.M{
    "$gt": fromDateS,
    "$lt": toDateS,
  },
}).All(&results)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question