【发布时间】:2020-02-03 21:04:48
【问题描述】:
我正在尝试使用 MongoDB 为我的 REST API 实现一个数据库,该数据库能够存储和检索具有特定字段的文档。
我可以轻松使用 mongoose,但我希望使用 MongoDB 的本地驱动程序,因为我想学习 MongoDB 而不是 mongoose。
{
"$jsonSchema": {
"bsonType": "object",
"required": [
"name",
"email"
],
"properties": {
"name": {
"bsonType": "string"
},
"email": {
"bsonType": "string"
},
"profileImagePath": {
"bsonType": "string"
},
"blogs": {
"bsonType": ["object"]
}
}
}
}
我希望只能插入诸如
之类的数据 "name" : "john",
"email" : "john@gmail.com"
或者
"name" : "john",
"email" : "john@gmail.com",
"profileImagePath" : "somePath"
但不是
"name" : "john",
"email" : "john@gmail.com",
"height" : "5'11"
由于没有在属性中指定高度。
【问题讨论】:
标签: mongodb schema jsonschema