/docs/40/50.md

http://github.com/osinka/subset · Markdown · 29 lines · 21 code · 8 blank · 0 comment · 0 complexity · 6a905b527ef5ea09e7b062939e12bb20 MD5 · raw file

  1. # Type Modification
  2. A field may be used to generate other instances of `Field`. This can
  3. be convenient to alter the type or name of a field. Since `Field` is
  4. immutable, it simply generates another instance.
  5. ## Index
  6. When defining indexes, MongoDB lets define ascending or descending
  7. order, hence the same field name is used as a key, but value is `Int`
  8. regardless of the original type it has. So, `Field[T]` has method
  9. `int` to quickly create a `Field[Int]` with the same name:
  10. ```scala
  11. val userName = "uname".fieldOf[String]
  12. collection.ensureIndex(userName.int === 1, userName.int === -1)
  13. ```
  14. ## Any Field
  15. `Field[Any]` field (created by `any` method) may be helpful to write
  16. or read a field "as is". If you absolutely certain in what you are
  17. doing,
  18. ```scala
  19. collection.modify(userName === "john", userName.any.set(10566))
  20. ```
  21. * * *