Interface DocumentMapper
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Functional interface for transforming documents during collection cloning.
Allows custom transformation logic to be applied to each document as it's copied
from the source collection to the target collection.
Example usage:
// Add a timestamp to each document
DocumentMapper addTimestamp = doc -> {
doc.append("clonedAt", Instant.now());
return doc;
};
// Remove sensitive fields
DocumentMapper removeSensitive = doc -> {
doc.remove("password");
doc.remove("ssn");
return doc;
};
// Transform field values
DocumentMapper normalizeEmail = doc -> {
if (doc.containsKey("email")) {
doc.put("email", doc.getString("email").toLowerCase());
}
return doc;
};
CollectionCloneSettings settings = CollectionCloneSettings.builder()
.documentMapper(addTimestamp)
.build();
-
Method Summary
Modifier and TypeMethodDescriptiondefault DocumentMapperandThen(DocumentMapper after) Returns a mapper that applies this mapper followed by the after mapper.static DocumentMapperidentity()Returns an identity mapper that returns the document unchanged.Transforms a document during the cloning process.
-
Method Details
-
map
Transforms a document during the cloning process.- Parameters:
document- the source document to transform- Returns:
- the transformed document to be inserted into the target collection
-
andThen
Returns a mapper that applies this mapper followed by the after mapper.- Parameters:
after- the mapper to apply after this mapper- Returns:
- a composed mapper that applies both transformations in sequence
-
identity
Returns an identity mapper that returns the document unchanged.- Returns:
- a mapper that performs no transformation
-