var fansSchema = new Schema({ openid: String, subscribe: Number, nickname: String, sex: Number, city: String, province: String, country: String, headimgurl: String, subscribe_time: Number, unionid: String, remark: String, groupid: Number, created_at: Number });
var messageSchema = new Schema({ fans: [{ type: Schema.Types.ObjectId, ref: ‘we_fans’ }], message: String, created_at: Number });
exports.Message = mongoose.model(‘we_message’,messageSchema);
exports.Fans = mongoose.model(‘we_fans’,fansSchema);
Message.find({ created_at: 1435734719 }).populate(‘fans’).exec(function(err, msg){ console.log(‘The Msg is %s’, msg);
});
这是我的模型文件 1个message 对应1个fans 取出来的结果是
fans 变成一个二维数组了 我希望取出一个一位数组 哪里写错了
fans: [{ type: Schema.Types.ObjectId, ref: ‘we_fans’ }],
fans: { type: Schema.Types.ObjectId, ref: ‘we_fans’ },
这两个是有区别的
哦知道了,感谢