Help in Mongoose and mongoDB with linked queries

1

I'm passing a query I made and it works on mongoDB to mongoose and it gives me an error.

The query in mongo DB is:

db.facturas.find({
    _id: {$in: db.detalles.distinct("id_factura",{category: ObjectId("5889eae21ffcc6da2c6b4ae4")})}
})

The category objectId is a parameter in the nodeJS APP

In the APP I have put together the query like this:

    Factura.find({'_id': {"$in": Detalle.distinct("id_factura",{qrycat})}})
    .populate('pto_venta')
    .populate('forma_pago')
    .exec(function(err, result) {
        if (err) res.send(err);
        res.json(result); 
    });

And I get the following error in NODEJS:

  

/var/nodejs/aadides-sgi/node_modules/express/lib/response.js:242    var body = JSON.stringify (val, replacer, spaces);                   ^

     

TypeError: Converting circular structure to JSON      at Object.stringify (native)      at ServerResponse.json (/var/nodejs/aadides-sgi/node_modules/express/lib/response.js:242:19)      at ServerResponse.send (/var/nodejs/aadides-sgi/node_modules/express/lib/response.js:151:21)      at /var/nodejs/aadides-sgi/app/handlers/facturasHandler.js:494:22      at /var/nodejs/aadides-sgi/node_modules/mongoose/lib/query.js:2176:21      at /var/nodejs/aadides-sgi/node_modules/kareem/index.js:160:11      at Query._find (/var/nodejs/aadides-sgi/node_modules/mongoose/lib/query.js:1019:5)      at /var/nodejs/aadides-sgi/node_modules/kareem/index.js:156:8      at /var/nodejs/aadides-sgi/node_modules/kareem/index.js:18:7      at _combinedTickCallback (internal / process / next_tick.js: 73: 7)      at process._tickCallback (internal / process / next_tick.js: 104: 9)   events.js: 160        throw er; // Unhandled 'error' event        ^

     

Error: read ECONNRESET      at exports._errnoException (util.js: 1018: 11)      at Pipe.onread (net.js: 568: 26)

    
asked by Ezequiel Cohort 14.08.2017 в 23:36
source

0 answers