remove _id from mongo result

Solution 1:

Try this solution:

app.get('/itesms', function(req, res) {
  items.find({}, { _id: 0 }).toArray(function (err, array) {
    res.send(array);
  })
});

Solution 2:

The usual .find({}, {_id:0}) approach wasn't working for me, so I went hunting and found in another SO answer that in version 3 of the Mongo API, you need to write it like this: .find({}, {projection:{_id:0}}). So, for example:

let docs = await db.collection("mycol").find({}, {projection:{_id:0}}).toArray();

It seems that (in the nodejs API, at least) you can also write it like this:

let docs = await db.collection("mycol").find({}).project({_id:0}).toArray();