我用猫鼬,我的mongodb中有这些数据:
"_id" : ObjectId("5f13e1edf7c56a896987c191"),
"deleted" : false,
"email" : "klinikkoding@gmail.com",
"firstName" : "Klinik",
"lastName" : "Koding",
"resetToken" : null,
"workspaces" : [
{
"status" : "active",
"_id" : ObjectId("5f13e124f7c56a896987c18e"),
"code" : "kk",
"name" : "Klinik Koding",
"_roleId" : ObjectId("5f13de3eb33fa33ce2a3b0dd")
},
{
"status" : "invited",
"_id" : ObjectId("5f13e13ff7c56a896987c190"),
"code" : "rm",
"name" : "The Manage",
"_roleId" : ObjectId("5f13de3eb33fa33ce2a3b0dd")
}
],
如何仅返回一个工作区?我需要的输出是这样的:
"_id" : ObjectId("5f13e1edf7c56a896987c191"),
"deleted" : false,
"email" : "klinikkoding@gmail.com",
"firstName" : "Klinik",
"lastName" : "Koding",
"resetToken" : null,
"workspaces" : [
{
"status" : "active",
"_id" : ObjectId("5f13e124f7c56a896987c18e"),
"code" : "kk",
"name" : "Klinik Koding",
"_roleId" : ObjectId("5f13de3eb33fa33ce2a3b0dd")
},
],
有人可以帮助我进行此查询吗?
答案 0 :(得分:0)
尝试一下。
async function retrieve(){
// You can retrieve it by any field. I used email because it is unique.
let data=await yourModelName.findOne({email:"klinikkoding@gmail.com"})
data.workspaces.splice(1,1)
console.log("your final result",data)
}
retrieve()