@@ -40,6 +40,7 @@ public final class ChangeStreamDocument<TDocument> {
40
40
@ BsonProperty ("ns" )
41
41
private final MongoNamespace namespace ;
42
42
private final TDocument fullDocument ;
43
+ private final BsonDocument documentKey ;
43
44
private final OperationType operationType ;
44
45
private final UpdateDescription updateDescription ;
45
46
@@ -48,6 +49,7 @@ public final class ChangeStreamDocument<TDocument> {
48
49
*
49
50
* @param resumeToken the resume token
50
51
* @param namespace the namespace
52
+ * @param documentKey a document containing the _id of the changed document
51
53
* @param fullDocument the fullDocument
52
54
* @param operationType the operation type
53
55
* @param updateDescription the update description
@@ -56,10 +58,12 @@ public final class ChangeStreamDocument<TDocument> {
56
58
public ChangeStreamDocument (@ BsonProperty ("resumeToken" ) final BsonDocument resumeToken ,
57
59
@ BsonProperty ("namespace" ) final MongoNamespace namespace ,
58
60
@ BsonProperty ("fullDocument" ) final TDocument fullDocument ,
61
+ @ BsonProperty ("documentKey" ) final BsonDocument documentKey ,
59
62
@ BsonProperty ("operationType" ) final OperationType operationType ,
60
63
@ BsonProperty ("updateDescription" ) final UpdateDescription updateDescription ) {
61
64
this .resumeToken = resumeToken ;
62
65
this .namespace = namespace ;
66
+ this .documentKey = documentKey ;
63
67
this .fullDocument = fullDocument ;
64
68
this .operationType = operationType ;
65
69
this .updateDescription = updateDescription ;
@@ -92,6 +96,21 @@ public TDocument getFullDocument() {
92
96
return fullDocument ;
93
97
}
94
98
99
+ /**
100
+ * Returns a document containing just the _id of the changed document.
101
+ * <p>
102
+ * For unsharded collections this contains a single field, _id, with the
103
+ * value of the _id of the document updated. For sharded collections,
104
+ * this will contain all the components of the shard key in order,
105
+ * followed by the _id if the _id isn’t part of the shard key.
106
+ * </p>
107
+ *
108
+ * @return the document key
109
+ */
110
+ public BsonDocument getDocumentKey () {
111
+ return documentKey ;
112
+ }
113
+
95
114
/**
96
115
* Returns the operationType
97
116
*
@@ -134,20 +153,22 @@ public boolean equals(final Object o) {
134
153
135
154
ChangeStreamDocument <?> that = (ChangeStreamDocument <?>) o ;
136
155
137
- if (!getResumeToken ().equals (that .getResumeToken ())) {
156
+ if (resumeToken != null ? !resumeToken .equals (that .resumeToken ) : that .resumeToken != null ) {
157
+ return false ;
158
+ }
159
+ if (namespace != null ? !namespace .equals (that .namespace ) : that .namespace != null ) {
138
160
return false ;
139
161
}
140
- if (! getNamespace () .equals (that .getNamespace ()) ) {
162
+ if (fullDocument != null ? ! fullDocument .equals (that .fullDocument ) : that . fullDocument != null ) {
141
163
return false ;
142
164
}
143
- if (! getFullDocument () .equals (that .getFullDocument ()) ) {
165
+ if (documentKey != null ? ! documentKey .equals (that .documentKey ) : that . documentKey != null ) {
144
166
return false ;
145
167
}
146
- if (getOperationType () != that .getOperationType () ) {
168
+ if (operationType != that .operationType ) {
147
169
return false ;
148
170
}
149
- if (getUpdateDescription () != null ? !getUpdateDescription ().equals (that .getUpdateDescription ())
150
- : that .getUpdateDescription () != null ) {
171
+ if (updateDescription != null ? !updateDescription .equals (that .updateDescription ) : that .updateDescription != null ) {
151
172
return false ;
152
173
}
153
174
@@ -156,20 +177,22 @@ public boolean equals(final Object o) {
156
177
157
178
@ Override
158
179
public int hashCode () {
159
- int result = getResumeToken ().hashCode ();
160
- result = 31 * result + getNamespace ().hashCode ();
161
- result = 31 * result + getFullDocument ().hashCode ();
162
- result = 31 * result + getOperationType ().hashCode ();
163
- result = 31 * result + (getUpdateDescription () != null ? getUpdateDescription ().hashCode () : 0 );
180
+ int result = resumeToken != null ? resumeToken .hashCode () : 0 ;
181
+ result = 31 * result + (namespace != null ? namespace .hashCode () : 0 );
182
+ result = 31 * result + (fullDocument != null ? fullDocument .hashCode () : 0 );
183
+ result = 31 * result + (documentKey != null ? documentKey .hashCode () : 0 );
184
+ result = 31 * result + (operationType != null ? operationType .hashCode () : 0 );
185
+ result = 31 * result + (updateDescription != null ? updateDescription .hashCode () : 0 );
164
186
return result ;
165
187
}
166
188
167
189
@ Override
168
190
public String toString () {
169
- return "ChangeStreamOutput {"
191
+ return "ChangeStreamDocument {"
170
192
+ "resumeToken=" + resumeToken
171
193
+ ", namespace=" + namespace
172
194
+ ", fullDocument=" + fullDocument
195
+ + ", documentKey=" + documentKey
173
196
+ ", operationType=" + operationType
174
197
+ ", updateDescription=" + updateDescription
175
198
+ "}" ;
0 commit comments