[JAVA-741] Ability to disable validation for illegal characters in keys Created: 22/Jan/13 Updated: 19/Mar/13 Resolved: 22/Jan/13 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 2.10.1 |
| Fix Version/s: | 2.11.0 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Steve Briskin (Inactive) | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
For use in internal 10gen applications, not part of public interface. |
| Comments |
| Comment by auto [ 22/Jan/13 ] | ||||||||||||||
|
Author: {u'date': u'2013-01-22T21:10:30Z', u'email': u'jeff.yemin@10gen.com', u'name': u'Jeff Yemin'}Message: Merge pull request #99 from stevebriskin/master
| ||||||||||||||
| Comment by auto [ 22/Jan/13 ] | ||||||||||||||
|
Author: {u'date': u'2013-01-22T20:59:25Z', u'email': u'steve.briskin@10gen.com', u'name': u'Steve Briskin'}Message: | ||||||||||||||
| Comment by Jeffrey Yemin [ 22/Jan/13 ] | ||||||||||||||
|
Merged https://github.com/mongodb/mongo-java-driver/pull/99. | ||||||||||||||
| Comment by Jeffrey Yemin [ 22/Jan/13 ] | ||||||||||||||
|
Steve suggests another option which I like best: add an instanceof test for LazyDBObject. If true, don't validate. | ||||||||||||||
| Comment by Jeffrey Yemin [ 22/Jan/13 ] | ||||||||||||||
|
If the system property is just too awful, another option is to add it to the public API: DBCollection.setFieldNameValidationEnabled(boolean enabled). | ||||||||||||||
| Comment by Jeffrey Yemin [ 22/Jan/13 ] | ||||||||||||||
|
This could work
I don't like this much either. | ||||||||||||||
| Comment by Jeffrey Yemin [ 22/Jan/13 ] | ||||||||||||||
|
That won't work since MyCollection is an inner class: java: MyCollectionWrapper.java:25: an enclosing instance that contains com.mongodb.DBApiLayer.MyCollection is required | ||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 22/Jan/13 ] | ||||||||||||||
|
Don't think this is a good idea for public api at all. I can explain if you need more than this, but here is a quick sample:
| ||||||||||||||
| Comment by Steve Briskin (Inactive) [ 22/Jan/13 ] | ||||||||||||||
|
Aside from subclassing, wouldn't I need to pass a collection factory to Mongo & MongoClient so it returns the subclassed instance. That's a notable change to the public API. Re. package naming, I'd much prefer MyCollection to be changed from package to protected. | ||||||||||||||
| Comment by Jeffrey Yemin [ 22/Jan/13 ] | ||||||||||||||
|
Yes, it's possible, just very ugly. But give it a shot. Note that it will definitely break in 3.0. | ||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 22/Jan/13 ] | ||||||||||||||
|
Yes, you must subclass/wrap from the same package, but that is completely possible in your own class. | ||||||||||||||
| Comment by Jeffrey Yemin [ 22/Jan/13 ] | ||||||||||||||
|
MyCollection is package private so it can't be subclassed, and the insert method with shouldApply parameter is protected so can't be called. I don't see another way around this without an API change or an option. I don't want to support this going forward, but to get past this hurdle I recommend a system property to turn off the check, and a clear comment saying that this is not part of the public API and is subject to change without warning. | ||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 22/Jan/13 ] | ||||||||||||||
|
This can already be done by subclassing, or wrapping, the DBApiLayer.MyCollection impl and calling insert with shouldApply set to false. For update/save you can simply use $ops to bypass this check, and leave it to the server. |