【发布时间】:2021-07-25 13:13:24
【问题描述】:
实际上,我想更改结果中的一些数据,例如添加一行并从返回 json 中删除一行
这里是代码
const Ledgers = db.Ledgers;
const LedgersSync = db.LedgersSync;
const ledgerList=await Ledgers.find(queryObj)
queryObj["isTransfer"] = 0
const ledgerListSync=await LedgersSync.find(queryObj)
console.log('ledgerList',ledgerList)
console.log('ledgerListSync',ledgerListSync)
Array.prototype.push.apply(ledgerList,ledgerListSync);
return ledgerList
我得到的结果
{
"_id": "608bb0725cdd5f0c93d96da0",
"companyId": 294989,
"company_id": "60741775b9808d1d885e66d5",
"Name": "ABC Company",
"reservedName": "",
"uid": "4eb25490-8288-4841-a925-ed2512ad6d7b-000000c4",
}
我想要的结果
{
"_id": "608bb0725cdd5f0c93d96da0",
"new":test
}
添加新行并删除现有行...
【问题讨论】:
-
你想从 mongo 中删除一个文档(你称之为“行”)?
-
文档数据...要编辑
-
所以你想在 mongodb 中编辑数据?你应该使用 updateOne()
-
不只是想像我提到的那样显示输出......我只想编辑返回的json
-
所以搜索“投影”docs.mongodb.com/manual/reference/method/db.collection.find 并请澄清您的问题。
标签: node.js mongodb api postman