Allow referencing the $id field of dbrefs within an aggregation pipeline.
Closes: #4123 Original pull request: #4125.
This commit is contained in:
committed by
Mark Paluch
parent
daf12a6e2b
commit
cf38ba15bf
@@ -267,7 +267,7 @@ public final class Fields implements Iterable<Field> {
|
||||
*/
|
||||
public String getTarget() {
|
||||
|
||||
if (isLocalVar()) {
|
||||
if (isLocalVar() || pointsToDBRefId()) {
|
||||
return this.getRaw();
|
||||
}
|
||||
|
||||
@@ -296,6 +296,10 @@ public final class Fields implements Iterable<Field> {
|
||||
return raw.startsWith("$$") && !raw.startsWith("$$$");
|
||||
}
|
||||
|
||||
protected boolean pointsToDBRefId() { // see https://jira.mongodb.org/browse/SERVER-14466
|
||||
return raw.endsWith(".$id");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @since 1.10
|
||||
|
||||
@@ -117,6 +117,13 @@ public class FieldsUnitTests {
|
||||
assertThat(Fields.field("$$$$target").getTarget()).isEqualTo("target");
|
||||
}
|
||||
|
||||
@Test // GH-4123
|
||||
public void keepsRawMappingToDbRefId() {
|
||||
|
||||
assertThat(Fields.field("$id").getName()).isEqualTo("id");
|
||||
assertThat(Fields.field("person.$id").getTarget()).isEqualTo("person.$id");
|
||||
}
|
||||
|
||||
private static void verify(Field field, String name, String target) {
|
||||
|
||||
assertThat(field).isNotNull();
|
||||
|
||||
Reference in New Issue
Block a user