Model.count using aggregate pipeline

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Works as Designed
    • Priority: Critical - P2
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I noticed `Model.count` was slow, after looking into the logs I noticed its doing `db.model.aggregate([{'$match': {} }, { '$group': { _id: 1, count:

      { '$sum': 1 }

      } }])`. This seems very very odd and explains why this is slow. I would expect it to use `db.model.find({}).count()` (if i do `Model.collection.count` it is fast, as i would expect cause its using the db.model.find({}).count()`)

              Assignee:
              Unassigned
              Reporter:
              Jonathon Gardner
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: