我有一个用于保存信息的架构,在此信息中,我有一个userId
,并且我想返回该架构的信息并返回用户表单user
架构的信息。
TravelRequestSchema:
const TravelRequestSchema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: "User" }
description: { type: String, require: true }
}, {
toObject: { virtuals: true },
toJSON: { virtuals: true }
});
用户架构:
const UserSchema = new Schema({
firstName: { type: String },
lastName: { type: String },
phoneNumber: { type: String },
email: { type: String, defult: null }
},{
toJSON: { virtuals: true }
});
现在我为获取信息写了这个问题:
await TravelRequestModel.find({})
.populate('User')
.exec();
但它不会返回我的用户信息,它只会返回UserId
。
现在我该如何解决这个问题?
答案 0 :(得分:1)
您希望查询填充特定字段,而不是模型名称
$path = str_replace('\\', '/',WP_CONTENT_DIR . '/uploads/pdf-files');
$zip = new ZipArchive();
$filename = str_replace('\\', '/', WP_CONTENT_DIR . '/uploads/pdf-files/zip-file.zip');
if($zip->open($filename, ZipArchive::CREATE) !== true) {
die("Error open");
}
if(is_dir($path)) {
if($dh = opendir($path)) {
while(($file = readdir($dh)) !== false) {
$file_parts = pathinfo($file);
if($file_parts['extension'] == 'pdf') {
if($zip->addFile($path . '/' . $file) !== true) {
die("Error addFile");
} else {
echo $file . "\n";
}
}
}
closedir($dh);
}
}
if($zip->close() !== true) {
die("Error close");
}
echo content_url('uploads/pdf-files/zip-file.zip');
wp_die();
这是因为如果您有多个引用同一模型的字段,则希望能够选择要填充的字段。