1

Here is my code:

Task.findByIdAndUpdate({_id: req.params.task_id}, updateObj, {new: true}, function (err, updatedUser) {
            if (err) {
                return result.serverError(req, res)
            }
            result.success(req, res, updatedUser);
        });

It will return all fields,but i don't need '__v' and '_id',how should i do?Thanks.

mojizo
  • 37
  • 6

1 Answers1

1

I think mongoose-hidden is your want.

You can also use the method in this link: MongoDB: output 'id' instead of '_id'

if you just want dismiss __v, you can use versionKey option for mogoose. http://mongoosejs.com/docs/guide.html#versionKey

Document versioning can also be disabled by setting the versionKey to false. DO NOT disable versioning unless you know what you are doing.

new Schema({..}, { versionKey: false });
var Thing = mongoose.model('Thing', schema);
var thing = new Thing({ name: 'no versioning please' });
thing.save(); // { name: 'no versioning please' }
Community
  • 1
  • 1
BlackMamba
  • 10,054
  • 7
  • 44
  • 67