/** * Puts the given value into the backing {@link Document} based on the coordinates defined through the given * {@link MongoPersistentProperty}. By default this will be the plain field name. But field names might also consist * of path traversals so we might need to create intermediate {@link BasicDocument}s. * * @param prop must not be {@literal null}. * @param value */ public void put(MongoPersistentProperty prop, @Nullable Object value) { Assert.notNull(prop, "MongoPersistentProperty must not be null!"); String fieldName = prop.getFieldName(); if (!fieldName.contains(".")) { BsonUtils.addToMap(document, fieldName, value); return; } Iterator<String> parts = Arrays.asList(fieldName.split("\\.")).iterator(); Bson document = this.document; while (parts.hasNext()) { String part = parts.next(); if (parts.hasNext()) { document = getOrCreateNestedDocument(part, document); } else { BsonUtils.addToMap(document, part, value); } } }
/** * Puts the given value into the backing {@link Document} based on the coordinates defined through the given * {@link MongoPersistentProperty}. By default this will be the plain field name. But field names might also consist * of path traversals so we might need to create intermediate {@link BasicDocument}s. * * @param prop must not be {@literal null}. * @param value */ public void put(MongoPersistentProperty prop, @Nullable Object value) { Assert.notNull(prop, "MongoPersistentProperty must not be null!"); String fieldName = prop.getFieldName(); if (!fieldName.contains(".")) { BsonUtils.addToMap(document, fieldName, value); return; } Iterator<String> parts = Arrays.asList(fieldName.split("\\.")).iterator(); Bson document = this.document; while (parts.hasNext()) { String part = parts.next(); if (parts.hasNext()) { document = getOrCreateNestedDocument(part, document); } else { BsonUtils.addToMap(document, part, value); } } }