[SERVER-27902] mongoDB Validations: How to apply mongoDB validation for Multiple elements of json of Array. Created: 03/Feb/17 Updated: 04/Feb/17 Resolved: 04/Feb/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Storage |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | monika | Assignee: | Kelsey Schubert |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
Hi Team, I might have posted the question with incorrect components or may be project. But the question is regarding validation feature in mongoDB. Please help me on it. Question: I have done rigorous search about it and could not find anything helpful. Please let me know how to apply validation for multiple elements for array of json for insert/update. Validation is a great feature in mongoDB and I would like to keep it using. Thanks. |
| Comments |
| Comment by Kelsey Schubert [ 04/Feb/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi monika123, Thanks for clarifying what you're trying to do. To achieve the desired functionality, please use $elemMatch. Specifically, I believe the following works for your use-case:
Please note that SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-users group. Kind regards, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by monika [ 04/Feb/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Thomas, Below are the steps that will help you understand my issue:- Step 1- Created a collection 'test'
Step 2- Applied Validations on the 'test' collection to implement the following checks-
Thanks | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kelsey Schubert [ 03/Feb/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi monika123, I just did quick check with MongoDB 3.4.1 and was unable to reproduce the behavior you describe. Would you please clarify which version of MongoDB you are using, and provide steps to reproduce?
Thank you, |