pick
$pick
Returns a new object or dense array containing only the specified keys/indices from the input. Keys not present in the input are silently omitted from the result. For arrays, numeric indices are selected and the result is a dense (packed) array.
Parameters
- Array of key names or indices (string[]|number[], required): The keys/indices to retain.
Example
// Retain only 'id' and 'name' from an object
new Schema('object').transformer({$pick: ['id', 'name']})
// {id: 1, name: 'Alice', secret: 'xyz'} → {id: 1, name: 'Alice'}
// Select the first and third elements from an array
new Schema('array').transformer({$pick: [0, 2]})
// ['a', 'b', 'c', 'd'] → ['a', 'c']
// Strip sensitive fields from a user record before returning
new Schema('object').transformer({$pick: ['id', 'username', 'email', 'role']})