@@ -60,11 +60,12 @@ on a person by using the ``field`` macro.
6060 field :weight, type: Float
6161 end
6262
63- Below is a list of valid types for fields.
63+ The valid types for fields are as follows:
6464
6565- ``Array``
6666- ``BigDecimal``
67- - ``Boolean``
67+ - ``Mongoid::Boolean``, which may be specified simply as ``Boolean`` in the
68+ scope of a class which included ``Mongoid::Document``.
6869- ``Date``
6970- ``DateTime``
7071- ``Float``
@@ -76,10 +77,15 @@ Below is a list of valid types for fields.
7677- ``Regexp``
7778- ``Set``
7879- ``String``
79- - ``StringifiedSymbol``
80+ - ``Mongoid::StringifiedSymbol``, which may be specified simply as
81+ ``StringifiedSymbol`` in the scope of a class which included
82+ ``Mongoid::Document``.
8083- ``Symbol``
8184- ``Time``
82- - ``TimeWithZone``
85+ - ``ActiveSupport::TimeWithZone``
86+
87+ Mongoid also recognizes the string ``"Boolean"`` as an alias for the
88+ ``Mongoid::Boolean`` class.
8389
8490To define custom field types, refer to :ref:`Custom Field Types <custom-field-types>` below.
8591
@@ -517,6 +523,47 @@ you have three options:
517523 This query will find all values that are either a ``decimal128`` value or
518524 a string that match that value.
519525
526+
527+ Using Symbols Or Strings Instead Of Classes
528+ -------------------------------------------
529+
530+ Mongoid permits using symbols or strings instead of classes to specify the
531+ type of fields, for example:
532+
533+ .. code-block:: ruby
534+
535+ class Order
536+ include Mongoid::Document
537+
538+ field :state, type: :integer
539+ # Equivalent to:
540+ field :state, type: "integer"
541+ # Equivalent to:
542+ field :state, type: Integer
543+ end
544+
545+ Only standard field types as listed below can be specified using symbols or
546+ strings in this manner. Mongoid recognizes the following expansions:
547+
548+ - ``:array`` => ``Array``
549+ - ``:big_decimal`` => ``BigDecimal``
550+ - ``:binary`` => ``BSON::Binary``
551+ - ``:boolean`` => ``Mongoid::Boolean``
552+ - ``:date`` => ``Date``
553+ - ``:date_time`` => ``DateTime``
554+ - ``:float`` => ``Float``
555+ - ``:hash`` => ``Hash``
556+ - ``:integer`` => ``Integer``
557+ - ``:object_id`` => ``BSON::ObjectId``
558+ - ``:range`` => ``Range``
559+ - ``:regexp`` => ``Regexp``
560+ - ``:set`` => ``Set``
561+ - ``:string`` => ``String``
562+ - ``:stringified_symbol`` => ``StringifiedSymbol``
563+ - ``:symbol`` => ``Symbol``
564+ - ``:time`` => ``Time``
565+
566+
520567.. _field-default-values:
521568
522569Specifying Field Default Values
@@ -1209,6 +1256,7 @@ alter the criteria to match the current locale.
12091256 Product.where(description: "Marvelous!")
12101257 # The resulting MongoDB query filter: { "description.en" : "Marvelous!" }
12111258
1259+
12121260Indexing
12131261--------
12141262
0 commit comments