@@ -60,11 +60,12 @@ on a person by using the ``field`` macro.
60
60
field :weight, type: Float
61
61
end
62
62
63
- Below is a list of valid types for fields.
63
+ The valid types for fields are as follows:
64
64
65
65
- ``Array``
66
66
- ``BigDecimal``
67
- - ``Boolean``
67
+ - ``Mongoid::Boolean``, which may be specified simply as ``Boolean`` in the
68
+ scope of a class which included ``Mongoid::Document``.
68
69
- ``Date``
69
70
- ``DateTime``
70
71
- ``Float``
@@ -76,10 +77,15 @@ Below is a list of valid types for fields.
76
77
- ``Regexp``
77
78
- ``Set``
78
79
- ``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``.
80
83
- ``Symbol``
81
84
- ``Time``
82
- - ``TimeWithZone``
85
+ - ``ActiveSupport::TimeWithZone``
86
+
87
+ Mongoid also recognizes the string ``"Boolean"`` as an alias for the
88
+ ``Mongoid::Boolean`` class.
83
89
84
90
To define custom field types, refer to :ref:`Custom Field Types <custom-field-types>` below.
85
91
@@ -517,6 +523,47 @@ you have three options:
517
523
This query will find all values that are either a ``decimal128`` value or
518
524
a string that match that value.
519
525
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
+
520
567
.. _field-default-values:
521
568
522
569
Specifying Field Default Values
@@ -1209,6 +1256,7 @@ alter the criteria to match the current locale.
1209
1256
Product.where(description: "Marvelous!")
1210
1257
# The resulting MongoDB query filter: { "description.en" : "Marvelous!" }
1211
1258
1259
+
1212
1260
Indexing
1213
1261
--------
1214
1262
0 commit comments