【发布时间】:2021-08-09 13:08:27
【问题描述】:
如何在 mongoDb 模式中声明不同类型的数组?
我在文档中有一个值,它可以是 double 或 int,我尝试像这样声明它:
"numberOf": {
"bsonType": ["long", "int"]
},
我收到了那个错误:
属性“numberOf”的类型无效:不支持类型 [long,int]
在doc 中,他们说您可以声明一个 bsonTypes 数组或类似的类型:
"type": "<JSON Type>" | ["<JSON Type>", ...],
"bsonType": "<BSON Type>" | ["<BSON Type>", ...],
我也试过了:
"numberOf": {
"type": "number"
},
我无法保存我的架构得到这个:
我不知道我错过了什么。
【问题讨论】:
-
我不知道这是什么 -
["long", "int"]。如果要定义多种类型,请使用"bsonType": "int" | "long" | "double" | "decimal", -
我试过了,还是不行
-
“它不起作用”相当模糊。你能澄清你尝试了什么,什么不起作用吗?请更新问题的详细信息。
-
我只想在我的属性上有多个 bsonTypes。应该很容易。例如,“numberOf”可以是 int 或 double。