Return all except some fields using findOne() in mongodb for node.js
0
votes
3
answers
5204
views
I am trying to use the following script to query for a document but the returned document still contains the field (password) that I don't want.
const client = await MongoClient.connect(
MONGODB_CONNECTION_STRING,
{ useUnifiedTopology: true }
);
const db = client.db(DB_NAME);
const collection = db.collection(collectionName);
const data = await collection
.find(
{
_id: someId
},
{
password: 0
}
);
It supposed to work as I have read in the mongodb documentation but I didn't find any documentation on findOne in mongodb for node.js.
Asked by picklu
(101 rep)
Jan 7, 2020, 01:39 PM
Last activity: Apr 1, 2022, 06:25 PM
Last activity: Apr 1, 2022, 06:25 PM