gpt4 book ai didi

json - 无法从 JSON 对象中删除字段 - Node JS

转载 作者:太空宇宙 更新时间:2023-11-03 22:23:47 25 4
gpt4 key购买 nike

我有一条生成 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);
});
}
});
});

pdf 的内容是一个 JSON 对象,如下所示。

    [ { _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 }

我需要删除 _id 字段和 __V 字段。我尝试这样做:

    delete features._id

    delete features.__V

但是生成的PDF仍然包含id和__V字段

enter image description here

如何正确删除 Node 中的字段?

最佳答案

我在 Feature.find 末尾使用 .select 限制了字段

  .select("-__v -_id");

关于json - 无法从 JSON 对象中删除字段 - Node JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49896141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com