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