N
N
Never Ever2022-02-14 15:52:20
go
Never Ever, 2022-02-14 15:52:20

How to search by time in monge?

Hello.
In monge, my data is stored like this.
And you need to search for this collection in time from and to

{
    "_id" : "62066dd01f50e385be38d9d1",
    "updated_at" : "2022-02-11T11:22:54.166+02:00"
}
{
    "_id" :  "62066dd01f50e385be38d9a0",
    "updated_at" :  "2022-02-14T14:14:20.654+02:00"
}


I save it to the database like this
order.Updated_At = time.Now()

. But there was a problem, since the front sends the time in this format
"date_from": "2022-02-14 00:00:00
" use it, but something doesn’t grow together as it should (
fromDate, _ :=  time.Parse("02/01/2006 15:04:05",  "2022-02-14 00:00:00")
toDate, _ :=  time.Parse("02/01/2006 15:04:05",  "2022-02-14 23:59:59")
  filter := bson.M{
    "updated_at": bson.M{
      "$gte": fromDate,
      "$lte": toDate,
    },
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FedorWK, 2022-02-20
@FedorWK

It is necessary to bring the first layout parameter to the format of the input data. In this case it will be "2006-02-01 15:04:05
"

fromDate, _ :=  time.Parse("2006-02-01 15:04:05", "2022-02-14 00:00:00")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question