如何从MongoDB中选择单列?

时间:2016-11-02 07:36:22

标签: mongodb

我有以下架构的用户表

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
});

我想获取特定用户的msges。我有用户名。目前这就是我正在做的事情

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);
            }
        }
        );
}

但我不想要所有的领域。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

它应该是这样的

False
相关问题