【发布时间】:2021-08-15 20:50:33
【问题描述】:
我有两个架构:
const book = new mongoose.Schema({
title: String
pages: Number
description: String
author: { type: mongoose.Schema.Types.ObjectId, ref: 'Author' }
}
const Book = mongoose.model('Book', BookSchema)
const Author = new mongoose.Schema({
name: String
age: Number
countryBorn: String
}
const Author = mongoose.model('Author', AuthorSchema)
调用 API 后,我想显示 Book Schema 中的数据列表。例如:
function Book(book){
const {title}, {pages}, {descritpion}, {author} = book;
return (
<h1> {title} <h1>
<p>{pages} , {description}<p>
<p>{author}<p>
);
}
对于 {author} 部分,当前显示 ObjectID “61422843cf091092020”,但我希望显示作者的姓名,例如“塞缪尔”。如何显示?
谢谢!
【问题讨论】:
标签: javascript node.js reactjs mongodb mongoose