These are chat archives for Automattic/mongoose

22nd
Dec 2017
Paul "Joey" Clark
@joeytwiddle
Dec 22 2017 03:03
@alavers It’s pretty dumb: it reattempts with an increasing delay. So it doesn’t know when the connection has reestablished, but it does “back off”.
Ours is not currently mongo-specific, but I was thinking it should only retry after certain error messages, so then it would be mongo-specific!
Jacques Uwamungu
@uwajacques_twitter
Dec 22 2017 09:49
Hi
newby to mongo
can anyone help me
i am trying to query data from the schema and categorise it by date,
I have the following data
  "results": [
    {
      "_id": "5a38eecc8d1325aa39685327",
      "updatedAt": "2017-11-19T10:49:48.937Z",
      "createdAt": "2017-12-19T10:49:48.937Z",
      "field1": "data",
      "field2": "data",
       "field3": "data"
    },
    {
      "_id": "5a38eecc8d1325aa39685327",
      "updatedAt": "2017-11-19T10:46:48.937Z",
      "createdAt": "2017-12-19T10:46:48.937Z",
      "field1": "data",
      "field2": "data",
       "field3": "data"
    },
    {
      "_id": "5a38eecc8d1325aa39685327",
      "updatedAt": "2017-10-19T10:49:48.937Z",
      "createdAt": "2017-12-19T10:49:48.937Z",
      "field1": "data",
      "field2": "data",
       "field3": "data"
    },
    {
      "_id": "5a38eecc8d1325aa39685327",
      "updatedAt": "2017-10-19T10:46:48.937Z",
      "createdAt": "2017-12-19T10:46:48.937Z",
      "field1": "data",
      "field2": "data",
       "field3": "data"
    },
    {
      "_id": "5a38eecc8d1325aa39685327",
      "updatedAt": "2017-9-19T10:49:48.937Z",
      "createdAt": "2017-9-19T10:49:48.937Z",
      "field1": "data",
      "field2": "data",
       "field3": "data"
    },
    {
      "_id": "5a38eecc8d1325aa39685327",
      "updatedAt": "2017-9-19T10:49:48.937Z",
      "createdAt": "2017-9-19T10:49:48.937Z",
      "field1": "data",
      "field2": "data",
       "field3": "data"
    },
     {
      "_id": "5a38eecc8d1325aa39685327",
      "updatedAt": "2017-8-19T10:49:48.937Z",
      "createdAt": "2017-8-19T10:49:48.937Z",
      "field1": "data",
      "field2": "data",
       "field3": "data"
    }
  ]
}
and i would like to query as the following format
  "results": {
    "2017-11-19": [ 
       {
          "_id": "5a38eecc8d1325aa39685327",
          "updatedAt": "2017-11-19T10:49:48.937Z",
          "createdAt": "2017-11-19T10:49:48.937Z",
          "field1": "data",
          "field2": "data",
           "field3": "data"
        },
        {
          "_id": "5a38eecc8d1325aa39685327",
          "updatedAt": "2017-11-19T10:46:48.937Z",
          "createdAt": "2017-11-19T10:46:48.937Z",
          "field1": "data",
          "field2": "data",
           "field3": "data"
        }
      ],
      "2017-10-19": [
        {
          "_id": "5a38eecc8d1325aa39685327",
          "updatedAt": "2017-10-19T10:49:48.937Z",
          "createdAt": "2017-10-19T10:49:48.937Z",
          "field1": "data",
          "field2": "data",
           "field3": "data"
        },
        {
          "_id": "5a38eecc8d1325aa39685327",
          "updatedAt": "2017-10-19T10:46:48.937Z",
          "createdAt": "2017-10-19T10:46:48.937Z",
          "field1": "data",
          "field2": "data",
           "field3": "data"
        }
      ],
      "2017-9-19": [
         {
            "_id": "5a38eecc8d1325aa39685327",
            "updatedAt": "2017-9-19T10:49:48.937Z",
            "createdAt": "2017-9-19T10:49:48.937Z",
            "field1": "data",
            "field2": "data",
             "field3": "data"
          },
          {
            "_id": "5a38eecc8d1325aa39685327",
            "updatedAt": "2017-9-19T10:49:48.937Z",
            "createdAt": "2017-9-19T10:49:48.937Z",
            "field1": "data",
            "field2": "data",
             "field3": "data"
          }
      ],
      "2017-8-19": [
        {
            "_id": "5a38eecc8d1325aa39685327",
            "updatedAt": "2017-8-19T10:49:48.937Z",
            "createdAt": "2017-8-19T10:49:48.937Z",
            "field1": "data",
            "field2": "data",
             "field3": "data"
          }
        ]
  }
}
Nick Karnik
@theoutlander
Dec 22 2017 19:17
@uwajacques_twitter you need to retrieve the data first
then, you can order it as you desire
Mongo will not change the structure of the data (AFAIK)
the simplest way is to use the map function
let orderedResults = results.map(r => { return new val })
Alexander Escamilla
@alexesca
Dec 22 2017 19:31
Does mongoose support MongoDB 3.6?
Alexander Escamilla
@alexesca
Dec 22 2017 19:41
Thank you. @theoutlander . Hope they support mongoDB 3.6 anytime soon. I will use the mongoDB driver meanwhile.
Juha Lindstedt
@pakastin
Dec 22 2017 21:36
I’m planning to try and switch to Fastify for latest MongoDB driver + schema validation..