Patrickkx
Patrickkx

Reputation: 1870

Omit specified field in collection while fetching it from mongodb

I have a database in mongodb, however, there's some field (userEmail) in every collection, that I dont want to fetch it to the client side.

I expect it to be something like:

User.find(callback)
    .limit(limit)
    .omit('userEmail');

I couldnt find it anywhere in the docs.

Upvotes: 1

Views: 54

Answers (1)

Ashh
Ashh

Reputation: 46451

You can use projection to limit your fields

User.find(callback).project({ userEmail: 0 }).limit(limit)

Upvotes: 1

Related Questions