使用模式填充猫鼬分页

时间:2021-06-23 08:11:52

标签: mongodb mongoose mongoose-schema mongoose-populate

我有两个集合 users 和 user_details

用户收集样本数据

{
"_id" : ObjectId("60d2e60d7164d8d761fc5e63"),
    "username" : "test",
     "email": "a@example.com"
}
user_details samples is 
{
"_id" : ObjectId("60cc3f83baa1941c85d8eee9"),
    "user_id": "60d2e60d7164d8d761fc5e63"
    "Address" : "Test add",
     "city": "test city"
}

In mongoose schema of user details
new mongoose.Schema({
    user_id: {
        type: String,
        ref: 'User',
      },
      Address : String,
      City : String,
}, { collection: 'user_details' });

While fetching it inside populate I have added it 
 populate: [
                
                { path: 'User'}
            ],

但用户详细信息未显示在结果中

0 个答案:

没有答案