0

I have a users table of the following schema

var usersSchema = mongoose.Schema({
  uname : {type : String , unique: true},
  email : {type : String},
  logintype : {type : String},
  password : String,
  status : String,
  hash : String,
  social: {},
  games: Object,
  os: String,
  friends: Object,
  msges:Object
});

I want to fetch msges of specific user. I have the username. Currently this is what I am doing

var getMessages = function(user){
    global.users.find({"uname" : uname},
        {"friends.friendUname":1,_id:0},
        function(err,doc){
            if(err){
                callback(false,err,"",null);
            }else{
                callback(true,null,"",doc);
            }
        }
        );
}

But I don't want all the fields. Any help?

Ali Zia
  • 3,825
  • 5
  • 29
  • 77
  • Please search before ask, Duplicate of http://stackoverflow.com/questions/24348437/mongoose-select-a-specific-field-with-find – molaga Nov 02 '16 at 07:45
  • I already searched before posting this question. I can't seem to get it right. Any ideas? – Ali Zia Nov 02 '16 at 07:48

1 Answers1

0

it should be something like this

global.users.find({"uname" : uname}, 'msges -_id', function (err, doc) {
    ...
})
molaga
  • 160
  • 1
  • 8