Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9131621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:10:13+00:00 2026-06-17T08:10:13+00:00

I am using mongoose with express and node to create a REST API. Upon

  • 0

I am using mongoose with express and node to create a REST API. Upon saving a new object, I want to return the object to the user. However, do not want to return some sensitive fields, like password, credit card details, permissions, billing history, etc.

I thought that there would be the equivalent of .select where you can select just a subset of fields to return to the user. However, it looks like this does not exist, and the ‘standard’ is just to delete fields you do not want to pass back to the user, like so:

  org.save(function(err, org) {
    if (err) return handleError(err, res);
    orgobj = org.toObject();
    delete orgobj.__v;
    delete orgobj._id;
    delete orgobj.billing;
    delete orgobj.plans;
    delete orgobj.permissions;
    return res.send(orgobj);
  });

Is there a more efficient way? I don’t like this, because if there is subsequently a field added, someone has to remember to specifically remove it. Also, I don’t want to ‘re-select’ the field either, for performance reasons.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:10:14+00:00Added an answer on June 17, 2026 at 8:10 am

    You may add a method, getPublicFields which returns an object containing strictly the public fields.

    orgSchema.methods.getPublicFields = function () {
        var returnObject = {
            name: this.name,
            address: this.address,
            randomField: this.randomField
        };
        return returnObject;
    };
    

    You may also add a callback to that function and perform some other queries to aggregate data, if you wish to do that. After the method is complete, just call

    var orgPublic = org.getPublicFields();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a node.js REST service running on mongoose and express. I'm also using
I'm trying the Develop a RESTful API Using Node.js With Express and Mongoose example
I am new to Node, and I'm using Mongoose as a driver for MongoDB.
I'm writing a node.js app using express and mongoose-auth. When I run my app,
I'm using Node.js + Express + Passport to create a simple authentication(local) and what
I am using node.js with express. I read out data from MongoDB with Mongoose
I wrote a simple application using node. It depends on express, mongodb and mongoose
Using express.js and everyauth with mongoose-auth, how can I create an external authentication route
Using Jade + Express + Node.js + Mongoose + MongoDB for my app, but
I've created a signup form using mongoose and express 3 Its possible the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.