D
D
Dmitry Afonchenko2018-06-27 18:06:34
MongoDB
Dmitry Afonchenko, 2018-06-27 18:06:34

How to group data in go using mgo?

Good day, comrades! There was a problem with mGo.
I have the following entities:

type Record struct {
  ID                      bson.ObjectId `bson:"_id,omitempty"`
  EndPoint                  string             `bson:"EndPoint"`
  ReceivedTime    time.Time      `bson:"ReceivedTime"`
}

type Message struct {
  ID                      bson.ObjectId `bson:"_id,omitempty"`
  EndPoint            string             `bson:"EndPoint"`
  ReceivedTime    time.Time      `bson:"ReceivedTime"`
}

How can I make a request to mongo using mgo, so that I end up with this structure?
type MessageRecordCount struct {
  EndPoint            string   `json:"EndPoint"`
  MessageCount   int        `json:"MessageCount"` 
  RecordCount      int        `json:"RecordCount"`
}

I need at least a tip where to look, since I'm not very good at monge and go yet.
Thanks in advance for your replies!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexkdev, 2018-07-10
@Indermove

Algorithm:

  1. Fetching from MongoDB
  2. You add data from other structures to the MessageRecordCount structure
  3. I understand that RecordCount is the number of records, then you need to make another request to MongoDB and put the result in your structure
  4. ...
  5. Profit!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question