I want to save documents like this:
_id: ObjectId('63fdf80e4ab6021dad4ed24b')
data: {
index: 1,
time: 1000,
dataFieldOne: 1.44
dataFieldTwo: 2.752
...
dataFieldN: 0.15
}
There can be any number of dataFieldN
attributes, but I want to make sure that data
object has at least one. For example, this would be an invalid document:
_id: ObjectId('63fdf80e4ab6021dad4ed24b')
data: {
index: 1,
time: 1000
}
Can I validate for this with MongoDB schema validation rules? If there is a solution, how efficient would it be?