need a better and efficient way

40 Views Asked by At

   exports.Country = async (req, res, err) => {

  MongoClient.connect(url, function (err, db) {
    if (err)
      send.json({ message: err.message, statuscode: err.status });
    var dbo = db.db(DATABASE);
    dbo.collection("countries").find({}, { projection: { _id: 0, iso2: 1, name: 1, } }).toArray(function (err, result) {
      if (err) {
        res.json({ message: err.message, statuscode: err.Response })
      };
      res.json({ success: true, statuscode: 200, response: result });
      db.close();
    })
  })
}

Hi everyone it is working fine but i think there should be a better way can someone suggest NOTE:I am doing this crud operations on a collection which does not have any schema i just imported json collection to my database

0

There are 0 best solutions below