我正在使用猫鼬为数据库建立一个网站,并且我目前正在尝试编写一条明确的路由,该路由不会发回以给定ID存储的数据,而是一个响应模式,其中包含每个属性的描述,属性的数据类型,以及该属性是否可选。
例如,这是我用于数据库中存储的每个产品的模型
const productSchema = new Schema({
name: {type: String, required: true},
description: { type: String, required: false },
image: {type: String, required: false},
expirationDate: { type: Date, required: true },
postedUser: { type: Schema.Types.ObjectId, ref: "User", required: true }
}, {
timestamps: true,
});
这是我编写的以给定产品ID检索数据的路线。
router.route('/').get((req, res, next) => {
Product.find(req.query)
.then(products => {
res.json(normalizer(products));
})
.catch(err => next(err));
});
类似于url localhost:5550 / product /?_ id = 5ef5521062186e0190da17c9如何返回以给定ID存储的数据,我想创建一条路由,该路由返回在调用url localhost:5550 / product时用于产品的模型/ schema /?_ id = 5ef5521062186e0190da17c9。
答案 0 :(得分:0)
您可以在模型上使用 else
{
echo "<tr><td colspan ='8' align='center'>No registered users!</td></tr>";
$sql = "ALTER TABLE etudiant AUTO_INCREMANT=1";
}
?>
</table>
<p align="center"><a href="Add.php"><button>Add a user</button></a></p>
</body>
</html>
属性来访问其模式
.schema
我不确定是router.route('/').get((req, res, next) => {
console.log(Product.schema)
res.json(Product.schema)
});
还是.schema
,您是否必须对其进行测试