Consultation with mongoose

0

I want to call all the names of a 'users' collection without the information that accompanies it, the query that I do brings all the information that is in the 'users' collection (name, surname, password) and I would just like to call the names excluding surname and password, is it possible?

    router.get('/getusers',getTypeUser, (req,res) => {
      const Users = require('../models/users');
      Users.find({typeuser:res.typeUser}).exec(function(err, Users ){
    if(err){
      console.log("Error");
    }else{
      res.json(Users);
    }
  })
})
    
asked by holman sneyder 05.06.2018 в 07:51
source

1 answer

1

I do not know if I understood you correctly, what you want to do is bring in the name only name ?. .find() , allows as a second parameter the fields you want.

  router.get('/getusers',getTypeUser, (req,res) => {
      const Users = require('../models/users');
      Users.find({typeuser:res.typeUser},'nombre').exec(function(err, Users ){
    if(err){
      console.log("Error");
    }else{
      res.json(Users);
    }
  })
})
    
answered by 05.06.2018 / 08:31
source