These are chat archives for Automattic/mongoose

16th
Jul 2018
Mihajlo Ilijić
@Pritilender
Jul 16 2018 07:59
@lineus I was thinking about how to have both count and find in the same aggregate and this looks great :D
Kev
@lineus
Jul 16 2018 09:00

thanks @Pritilender, I played with it a little more yesterday and changed it to

    {
      $match: {
        name: /name([0-9]){2}/
      }
    },
    {
      $facet: {
        users: [{ $skip: 10 }, { $limit: 10 }],
        n: [{ $count: 'n'}]
      }
    },
    { 
      $replaceRoot: { 
        newRoot: { 
          users: '$users', 
          count: { 
            $arrayElemAt: ['$n.n', 0] 
          } 
        } 
      } 
    }

which seems a little cleaner

Mihajlo Ilijić
@Pritilender
Jul 16 2018 09:16
Hm, yup. But what are the performance of this against double projection?
Kev
@lineus
Jul 16 2018 09:40
for the specific example in that gist, the double projection took 10.127 milliseconds, and the replaceRoot took 10.681 milliseconds.
after adding an index to the name path though, the replaceroot is faster by 1.2 milliseconds
Mihajlo Ilijić
@Pritilender
Jul 16 2018 13:05
cool
mongoosebot
@mongoosebot
Jul 16 2018 18:59
:tada: We just released version 5.2.4 :tada:

5.2.4 / 2018-07-16

  • docs: Model.insertMany rawResult option in api docs #6724 lineus
  • docs: fix typo on migrating to 5 guide #6722 iagowp
  • docs: update doc about keepalive #6719 #6718 simllll
  • fix: ensure debug mode doesn't crash with sessions #6712
  • fix(document): report castError when setting single nested doc to primitive value #6710
  • fix(connection): throw helpful error if using new db.model(foo)(bar) #6698
  • fix(model): throw readable error with better stack trace when non-cb passed to $wrapCallback() #6640