I'm following a tutorial and I can see the correct result from the console.log(result) in the console, but when I make the GET request from postman, it returns nothing. Why is send(200, JSON.parse(JSON.stringify(result)));
not working?
I also did a console.log(JSON.parse(JSON.stringify(result))) and it returns correctly the data correctly to the console. Just can't send it in response for some reason.
var MongoClient = require('mongodb').MongoClient;
var Post = require('./model/post');
module.exports = async function (context, req) {
let currentPage = 1;
context.log("process.env.CosmosDBConnectionString");
context.log(process.env.CosmosDBConnectionString);
MongoClient.connect(process.env.CosmosDBConnectionString, (err, client) => {
let send = response(client, context);
if (err) send(500, err.message);
console.log("DBNAME: " + process.env.dbName);
let db = client.db(process.env.dbName);
let queryDate = Date.now();
db.collection('listings').find({}) //test
.toArray((err, result) => {
console.log(result);
if (err) send(500, err.message);
send(200, JSON.parse(JSON.stringify(result)));
});
});
};
function response(client, context) {
return function (status, body) {
context.res = {
status: status,
body: body
};
client.close();
context.done();
};
}