/docs/40/50.md
http://github.com/osinka/subset · Markdown · 29 lines · 21 code · 8 blank · 0 comment · 0 complexity · 6a905b527ef5ea09e7b062939e12bb20 MD5 · raw file
- # Type Modification
- A field may be used to generate other instances of `Field`. This can
- be convenient to alter the type or name of a field. Since `Field` is
- immutable, it simply generates another instance.
- ## Index
- When defining indexes, MongoDB lets define ascending or descending
- order, hence the same field name is used as a key, but value is `Int`
- regardless of the original type it has. So, `Field[T]` has method
- `int` to quickly create a `Field[Int]` with the same name:
- ```scala
- val userName = "uname".fieldOf[String]
- collection.ensureIndex(userName.int === 1, userName.int === -1)
- ```
- ## Any Field
- `Field[Any]` field (created by `any` method) may be helpful to write
- or read a field "as is". If you absolutely certain in what you are
- doing,
- ```scala
- collection.modify(userName === "john", userName.any.set(10566))
- ```
- * * *