[JAVA-3086] How to retrieve validator for an existing collection? Created: 09/Nov/18 Updated: 11/Sep/19 Resolved: 09/Nov/18 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Tomasz Zarna | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Document validation can be specified when creating a new collection, see JAVA-2008, but is there a way to retrieve it after the collection has been created? In mongo Shell this can be easily achieved by running db.getCollectionInfos({name: "MyTestCollection"})[0].options.validator; What I miss is a similar method on the MongoDatabase class or a Database Command I can run with the MongoDatabase.runCommand(...) method. If there's currently no way to retrieve that information, would it be possible to turn this question into a feature request? |
| Comments |
| Comment by Jeffrey Yemin [ 09/Nov/18 ] |
|
Happy to hear you're unblocked. I agree that your suggestion may be a better API, but on the other hand it's not all that common for applications to need this functionality. If you still feel strongly about it, feel free to open a separate feature request for it. |
| Comment by Tomasz Zarna [ 09/Nov/18 ] |
|
That did the trick, thanks Jeff! I still think it would be great if I could retrieve the doc with the validator for a specific collection. Now I need to filter the result, looking for a collection I'm interested in i.e. database.listCollections().filter(Filters.eq("name", "MyTestCollection").first() |
| Comment by Jeffrey Yemin [ 09/Nov/18 ] |
|
Hi zaza Have you tried com.mongodb.client.MongoDatabase#listCollections(). The document that it returns should include the validator. If not, please let us know. |