-
Notifications
You must be signed in to change notification settings - Fork 626
Collection Group Queries #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
335d84f
3034b0a
407d9b8
3fc8914
b41687f
029578b
55246a2
273ad48
bd88e56
94693cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -324,20 +324,28 @@ private Query whereHelper(@NonNull FieldPath fieldPath, Operator op, Object valu | |
} | ||
if (value instanceof String) { | ||
String documentKey = (String) value; | ||
if (documentKey.contains("/")) { | ||
// TODO: Allow slashes once ancestor queries are supported | ||
if (documentKey.isEmpty()) { | ||
throw new IllegalArgumentException( | ||
"Invalid query. When querying with FieldPath.documentId() you must provide a valid " | ||
+ "document ID, but '" | ||
+ "document ID, but it was an empty string."); | ||
} | ||
if (!query.isCollectionGroupQuery() && documentKey.contains("/")) { | ||
throw new IllegalArgumentException( | ||
"Invalid query. When querying a collection by FieldPath.documentId() you must " | ||
+ "provide a plain document ID, but '" | ||
+ documentKey | ||
+ "' contains a '/' character."); | ||
} else if (documentKey.isEmpty()) { | ||
} | ||
ResourcePath path = query.getPath().append(ResourcePath.fromString(documentKey)); | ||
if (!DocumentKey.isDocumentKey(path)) { | ||
throw new IllegalArgumentException( | ||
"Invalid query. When querying with FieldPath.documentId() you must provide a valid " | ||
+ "document ID, but it was an empty string."); | ||
"Invalid query. When querying a collection group by FieldPath.documentId(), the " | ||
+ "value provided must result in a valid document path, but '" | ||
+ path | ||
+ "' is not because it has an odd number of segments (" | ||
+ path.length() | ||
+ ")."); | ||
} | ||
ResourcePath path = this.query.getPath().append(documentKey); | ||
hardAssert(path.length() % 2 == 0, "Path should be a document key"); | ||
fieldValue = | ||
ReferenceValue.valueOf(this.getFirestore().getDatabaseId(), DocumentKey.fromPath(path)); | ||
} else if (value instanceof DocumentReference) { | ||
|
@@ -655,15 +663,26 @@ private Bound boundFromFields(String methodName, Object[] values, boolean before | |
+ "."); | ||
} | ||
String documentId = (String) rawValue; | ||
if (documentId.contains("/")) { | ||
if (!query.isCollectionGroupQuery() && documentId.contains("/")) { | ||
throw new IllegalArgumentException( | ||
"Invalid query. Document ID '" | ||
"Invalid query. When querying a collection and ordering by FieldPath.documentId(), " | ||
+ "the value passed to " | ||
+ methodName | ||
+ "() must be a plain document ID, but '" | ||
+ documentId | ||
+ "' contains a slash in " | ||
+ "' contains a slash."); | ||
} | ||
ResourcePath path = query.getPath().append(ResourcePath.fromString(documentId)); | ||
if (!DocumentKey.isDocumentKey(path)) { | ||
throw new IllegalArgumentException( | ||
"Invalid query. When querying a collection group and ordering by " | ||
+ "FieldPath.documentId(), the value passed to " | ||
+ methodName | ||
+ "()."); | ||
+ "() must result in a valid document path, but '" | ||
+ path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional nit: the wording of this exception is different from the one above, even though they communicate the same thing. Would it be possible to add a helper method like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So these errors are actually redundant. I could get rid of the first one, but I think it will be hit more often, and by handling it separately we can make the error message a little clearer. That said, I did go back and forth on this. I'll think about it a bit more as I do the iOS port. |
||
+ "' is not because it contains an odd number of segments."); | ||
} | ||
DocumentKey key = DocumentKey.fromPath(query.getPath().append(documentId)); | ||
DocumentKey key = DocumentKey.fromPath(path); | ||
components.add(ReferenceValue.valueOf(firestore.getDatabaseId(), key)); | ||
} else { | ||
FieldValue wrapped = firestore.getDataConverter().parseQueryValue(rawValue); | ||
|
Uh oh!
There was an error while loading. Please reload this page.