2

I have a route that generates a PDF.

featureRoutes.route('/report/').get(function (req, res) {
Feature.find(function (err,features){
if(err){
 console.log(err);
}
else {
pdf.create(features.toString()).toStream(function (err, stream) {
  if (err) return res.send(err);
  res.type('pdf');
  stream.pipe(res);
});
}
});
});

The contents of the pdf is a JSON object that looks like this.

    [ { _id: 5ad5ddddcd054b2b5b20143c,
name: 'Project sidebar',
description: '<p>The project sidebar that we previewed in&nbsp;<a href="https://confluence.atlassian.com/jira/jira-6-4-release-notes-678561444.html">JIRA 6.4</a>&nbsp;is here to stay. We built this new navigation experience to make it easier for you to find what you need in your projects. It&#39;s even better, if you are using JIRA Agile: your backlog, sprints, and reports are now just a click away. If you&#39;ve used the sidebar with JIRA Agile before, you&#39;ll notice that cross-project boards, which include multiple projects, now have a project sidebar as well &mdash;&nbsp;albeit a simpler version.</p>\n',
__v: 0 }

I need to strip the _id field and the __V field. I try this by:

    delete features._id

and

    delete features.__V

But the PDF generated still includes the id and __V field

enter image description here

How to remove the fields properly in node?

4
  • Possible duplicate of Javascript delete object property not working Commented Apr 18, 2018 at 9:37
  • is features an array or json. from the code it looks like it is a json within array ? could it be delete features[0]._id Commented Apr 18, 2018 at 10:15
  • @Macintosh_89 - it does not deletes any item, I am using node 8.11 Commented Aug 23, 2018 at 9:22
  • Answer : stackoverflow.com/q/51982694/2034750 Commented Aug 23, 2018 at 10:11

1 Answer 1

0

I restricted the fields with a .select at the end of Feature.find

  .select("-__v -_id");
Sign up to request clarification or add additional context in comments.

2 Comments

How can you do it while create?
Please refer stackoverflow.com/q/51982694/2034750, it may helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.