Fix Query/BasicQuery getFieldsObject() inconsistency #345
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, Query.getFieldsObject() and BasicQuery.getFieldsObject()
would behave differently in the case of fields().include(). For
example:
Query query = new Query(jsonStr);
query.fields().include("name");
DBObject fieldsObject = query.getFieldsObject();
// fieldsObject contains name, based on the fieldspec
However,
Query query = new BasicQuery(jsonStr);
query.fields().include("name");
DBObject fieldsObject = query.getFieldsObject();
// fieldsObject is null, because BasicQuery was not created
// with a fieldsObject in the constructor
This fix changes BasicQuery to use the parent's getFieldsObject() in
the event that the BasicQuery was created without an explicit
fieldsObject in the constructor. In the case when an explicit
not-null FieldsObject was provided, it will defer to that
FieldsObject over using the parent class's getFieldsObject().
I ran into this while using BasicQuery but trying to use an
enumerated list of fields. I was confused why fields().include()
was working for Query but not BasicQuery. After stepping through
it in the debugger, I filed DATAMONGO-1387.
Issue: DATAMONGO-1387
My contributor number is: 165520160303021604