how to use the cursor in the mouse

Asked

Viewed 89 times

-1

when I will make the requisition to take the amounts of debts and credit of this error:

{
  "errors": [
    {
      "name": "MongoError",
      "message": "The 'cursor' option is required, except for aggregate with the explain argument",
      "ok": 0,
      "errmsg": "The 'cursor' option is required, except for aggregate with the explain argument",
      "code": 9,
      "codeName": "FailedToParse"
    }
  ]
}

I’ve seen some ways to use, but I don’t work at all, so I read from version 3.6 of Mongo you need to set the course, my version is "mongoose": "^4.7.0" and the teacher also, in video class he can make the request without using the cursor, he provides the working code, however the error persists here

the code

BillingCycle.route('summary', (req, res, next) => {
    BillingCycle.aggregate({
        $project: {credit: {$sum: "$credits.value"}, debt: {$sum:
        "$debts.value"}}
        }, {
        $group: {_id: null, credit: {$sum: "$credit"}, debt: {$sum: "$debt"}}
        }, {
        $project: {_id: 0, credit: 1, debt: 1}
        }, (error, result) => {
        if(error) {
            res.status(500).json({errors: [error]})
        } else {
        res.json(result[0] || { credit: 0, debt: 0 })
        }
    })
})

if you can place exactly where the cursor should be in this code would appreciate it very much, thanks from now.

  • I advise you to work on the latest version of Mongoose. If this is not possible this cursor error can be solved in the "Mongoose" version: "4.13.7"

2 answers

1

Hello it is possible to solve this problem by updating Mongoose, I tested with this version and it worked: npm install [email protected]

-1

Hello, I am doing the same exercise and I received the same error. I realized that in my bank was registered value in type String. I believe this is the error that is happening. Until because in the error message we have the return of "Codename": "Failedtoparse".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.