I'm familiar with variant
type of OCaml. For example,
type foo =
| Int of int
| Pair of int * string
I know how to define Number
and String
in MongoDB, but my question is how to define the variant type as above in MongoDB:
var PostSchema = new mongoose.Schema({
num: { type: Number },
name: { type: String },
variant: ???
})
Does anyone have any idea?
Edit 1: I just found this answer and this answer. They use classes or functions to mimic variant
. It works well in JavaScript in Front-end. However, the question is whether it is possible to put them in a Schema
?