Enforcing schema validation in MongoDB

前端 未结 2 1927
温柔的废话
温柔的废话 2021-01-03 06:30

I\'m looking for ways to validate that data being inserted into MongoDB matches a schema, e.g. has all the required fields and correct data types. I know Mongo itself is sc

相关标签:
2条回答
  • 2021-01-03 06:36

    Not sure if you're still looking but an object document mapper (ODM) would do the trick.

    I have checked out both Morphia or Spring Data - MongoDB and either would take care of your type safety concerns since they would map your documents directly to Java classes.

    0 讨论(0)
  • 2021-01-03 06:37

    In the upcoming Mongo 3.2 version they added document validation (slides).

    You can specify validation rules for each collection, using validator option using almost all mongo query operators (except $geoNear, $near, $nearSphere, $text, and $where). You can read more about it in one of my answers.

    0 讨论(0)
提交回复
热议问题