0

I would like to create a 'read x data' function to get x data from an object 'user' that is in an object array 'location'

I've tried this for read all data from one user

    read(req, res) {
    const id= req.params.id;
    data.find({id: id}).then((data) => {
        res.send({data});
    })
}

But I don't know how to make the same thing with an specific parameter

My Schema :

const UserSchema = new Schema({
  users : [
    {
      id : String,
      name : String,
      others : [
        location : { x : [String], y : [String]}
      ]
    }
  ]
})

I just want to receive the x data from an user like "bob" :

complete data schema

{
   "id" : 1,
   "name" : "bob",
   "others": [
     "location" : { "x" : ["here" : "london", "somewhere" : "home"], "y" : ["here" : "london", "somewhere" : "home"] }
   ]
}

what I want :

"x" : [
  "here" : "london",
   "somewhere" : "home"
]
Eldras00
  • 17
  • 8

1 Answers1

0

You can use Mongoose's select.