【发布时间】:2019-08-23 21:24:41
【问题描述】:
我想创建一个“读取 x 数据”函数来从对象数组“位置”中的对象“用户”获取 x 数据
我已经尝试过从一个用户那里读取所有数据
read(req, res) {
const id= req.params.id;
data.find({id: id}).then((data) => {
res.send({data});
})
}
但是我不知道如何用特定的参数做同样的事情
我的架构:
const UserSchema = new Schema({
users : [
{
id : String,
name : String,
others : [
location : { x : [String], y : [String]}
]
}
]
})
我只想从像“bob”这样的用户那里接收 x 数据:
完整的数据架构
{
"id" : 1,
"name" : "bob",
"others": [
"location" : { "x" : ["here" : "london", "somewhere" : "home"], "y" : ["here" : "london", "somewhere" : "home"] }
]
}
我想要什么:
"x" : [
"here" : "london",
"somewhere" : "home"
]
【问题讨论】:
-
我重新编辑了我的问题
-
我已经读过那个 Quastion 但它有所不同,因为我想要一个用户的所有“x”数据
标签: node.js mongodb mongoose mongodb-query