NodeJs is sending empty response

I am using NodeJS and MongoDb as a backend service.I am trying to retrieve distinct data based on condition like I want to get names where order status is pending:

const coll = client.db("My_db").collection("Orders");

                  let output = => ({'name'}));


But it is sending empty array like this:


Someone please let me know what I am doing wrong.Any help would be appreciated.


As per documentation Distinct Mongo DB

Thay result will be array .But you are matching its a object key .

So do with argument only

let output = => ({'name':r}));

Node.js return empty response � Issue #1013 � nodejs/node-v0.x , We have created application to grap gtalk user information like status, send chat message and etc with the "node.js". This functionalities working fine. But, When� use response.send() or res.send() function instead – Binit Ghetiya Nov 26 '16 at 5:21. Browse other questions tagged javascript node.js or ask your own question.

You don't need to run map over that response. The distinct function returns the array of distinct values. Try console.log(docs) and check it

http module error out while sending empty response body � Issue , But due to empty body and response nodejs is crashing. Hope I am clear with my issue . res.status(response.statusCode).send() will definitely crash if response is undefined so response = response || {} is the workaround for that and the code is breaking because we are trying to call res.status(null).send({}). as the status field is undefined node is breaking. Should it be handled or it is expected?

Because you have specified field as name, you don't need to use, just use r

You can refer to the link, hope this will help you :)

If your MongoDB is above 2.2 and you want to find multiple fields, you can use aggregate

collection = db.tb;
  {"$group": { "_id": { name: "$name", email: "$email" } } }

Send a response using Express, How to send a response back to the client using Express. Use end() to send an empty response. An alternative way to send Download my free Express.js Handbook, and check out my premium Node.js Course � Home. Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.

Node.js returning empty response for HTTPS - node.js - html, Node.js returning empty response for HTTPS - node.js. sending a request from a Node.js client: var http = require("http"); var options = { "hostname": "localhost"� The res object is an enhanced version of the response object found in Node.js. Sending a response. There are multiple ways to send responses using Express, and we'll go through a few examples now. res.send() Sending a response can be achieved by calling the res.send() method.

Node js Fetch send empty body : node, Node js Fetch send empty body. Hi, I'm creating console.log(response). }) }); I guess you should only send „JSON.stringify(body)“ not wrapped again. level 2. Here we used the Response.send() method, which accepts any string.. You can send JSON to the client by using Response.json(), a useful method.. It accepts an object or array, and converts it to JSON before sending it:

request.Response.body JavaScript and Node.js code examples , clientParam.url }).then(function (response) { return response.body; }) function( error, response, body) { if (error) { console.log('Error sending message: ', error); } � When it comes to Node.js there are a fair amount of solutions to this problem both built into the language and by the community. Let’s take a look at some of the most popular ones. We’ll be using NASA’s Astronomy Picture of the Day API as the JSON API that we are interacting with in all of these examples because space is the coolest thing

  • can you try to console.log the output variable ?
  • On doing console.log() its showing {name:undefined}
  • Are you positive you're showing us the correct route handler? Can you try res.send("test"); instead to make sure? Because I don't see how the above code could result in the response you posted.
  • Everything is correct I got the solution thw problem was in i need to use only r.Now it is showing proper names.
  • Print out docs object with console.log(docs);. let's check error first.
  • What if i want to get phone number along with name.
  • you could do with aggregation group for example .Still i m also learning mongo db