大家好,在过去的几天里,我一直在尝试各种组合,以确定如何创建模式验证器。这意味着集合不会只接受任何输入,而只接受验证器中给定的内容。我在春天通过mongo-repository创建了下面的集合。你能提供同样的验证器吗?还提供了将复杂的mongodb集合映射到java pojo的链接。这会有很大的帮助。我发现的只是简单的验证器或java to mongo集合,反之亦然。
{
"_id": {
"$numberInt": "1"
},
"listOfItems": [
{
"itemid": {
"$numberInt": "1"
},
"qty": {
"$numberInt": "10"
},
"qty_type": "kg",
"cost": "20",
"currency": "INR"
},
{
"itemid": {
"$numberInt": "2"
},
"qty": {
"$numberInt": "10"
},
"qty_type": "kg",
"cost": "20",
"currency": "INR"
},
{
"itemid": {
"$numberInt": "3"
},
"qty": {
"$numberInt": "10"
},
"qty_type": "kg",
"cost": "20",
"currency": "INR"
}
],
"_class": "com.daily.essential.cartservice.model.Cart"
}发布于 2020-04-21 10:05:43
//这应该可以回答您的问题
const mongoose = require('mongoose');
const productSchema = mongoose.Schema({
//mongoose为产品_id生成一个新的rando唯一Id : mongoose.Schema.Types.ObjectId,//mongoose确保用户输入的name是一个字符串,mongoose将/name字段设置为必填字段,这意味着用户不能将该字段留空。name:{type: String,必需: true},//mongoose会确保用户输入的价格是一个数字,并且mongoose会使//价格字段为必填字段,这意味着用户不能将该字段留空。价格:{type:数字,必填: true} });
module.exports =mongoose.model(‘产品’,productSchema);
https://stackoverflow.com/questions/61332799
复制相似问题