@@ -1070,17 +1070,22 @@ public WriteResult remove(Object object, String collection) {
1070
1070
}
1071
1071
1072
1072
/**
1073
- * Returns {@link Entry} containing the {@link MongoPersistentProperty} defining the {@literal id} as
1074
- * {@link Entry#getKey()} and the {@link Id}s property value as its {@link Entry#getValue()}.
1073
+ * Returns {@link Entry} containing the field name of the id property as {@link Entry#getKey()} and the {@link Id}s
1074
+ * property value as its {@link Entry#getValue()}.
1075
1075
*
1076
1076
* @param object
1077
1077
* @return
1078
1078
*/
1079
- private Map . Entry <MongoPersistentProperty , Object > extractIdPropertyAndValue (Object object ) {
1079
+ private Entry <String , Object > extractIdPropertyAndValue (Object object ) {
1080
1080
1081
1081
Assert .notNull (object , "Id cannot be extracted from 'null'." );
1082
1082
1083
1083
Class <?> objectType = object .getClass ();
1084
+
1085
+ if (object instanceof DBObject ) {
1086
+ return Collections .singletonMap (ID_FIELD , ((DBObject ) object ).get (ID_FIELD )).entrySet ().iterator ().next ();
1087
+ }
1088
+
1084
1089
MongoPersistentEntity <?> entity = mappingContext .getPersistentEntity (objectType );
1085
1090
MongoPersistentProperty idProp = entity == null ? null : entity .getIdProperty ();
1086
1091
@@ -1090,7 +1095,7 @@ private Map.Entry<MongoPersistentProperty, Object> extractIdPropertyAndValue(Obj
1090
1095
1091
1096
Object idValue = BeanWrapper .create (object , mongoConverter .getConversionService ())
1092
1097
.getProperty (idProp , Object .class );
1093
- return Collections .singletonMap (idProp , idValue ).entrySet ().iterator ().next ();
1098
+ return Collections .singletonMap (idProp . getFieldName () , idValue ).entrySet ().iterator ().next ();
1094
1099
}
1095
1100
1096
1101
/**
@@ -1101,8 +1106,8 @@ private Map.Entry<MongoPersistentProperty, Object> extractIdPropertyAndValue(Obj
1101
1106
*/
1102
1107
private Query getIdQueryFor (Object object ) {
1103
1108
1104
- Map . Entry <MongoPersistentProperty , Object > id = extractIdPropertyAndValue (object );
1105
- return new Query (where (id .getKey (). getFieldName () ).is (id .getValue ()));
1109
+ Entry <String , Object > id = extractIdPropertyAndValue (object );
1110
+ return new Query (where (id .getKey ()).is (id .getValue ()));
1106
1111
}
1107
1112
1108
1113
/**
@@ -1116,7 +1121,7 @@ private Query getIdInQueryFor(Collection<?> objects) {
1116
1121
Assert .notEmpty (objects , "Cannot create Query for empty collection." );
1117
1122
1118
1123
Iterator <?> it = objects .iterator ();
1119
- Map . Entry <MongoPersistentProperty , Object > firstEntry = extractIdPropertyAndValue (it .next ());
1124
+ Entry <String , Object > firstEntry = extractIdPropertyAndValue (it .next ());
1120
1125
1121
1126
ArrayList <Object > ids = new ArrayList <Object >(objects .size ());
1122
1127
ids .add (firstEntry .getValue ());
@@ -1125,7 +1130,7 @@ private Query getIdInQueryFor(Collection<?> objects) {
1125
1130
ids .add (extractIdPropertyAndValue (it .next ()).getValue ());
1126
1131
}
1127
1132
1128
- return new Query (where (firstEntry .getKey (). getFieldName () ).in (ids ));
1133
+ return new Query (where (firstEntry .getKey ()).in (ids ));
1129
1134
}
1130
1135
1131
1136
private void assertUpdateableIdIfNotSet (Object entity ) {
0 commit comments