@@ -102,7 +102,7 @@ MongoDB indexes are data structures that improve query efficiency by reducing
102
102
the number of documents needed to retrieve results of a query. Indexes such as
103
103
geospatial indexes extend the ways in which you can query the data.
104
104
105
- To improve query performance by using an index, make sure the query is
105
+ To improve query performance by using an index, make sure the query is
106
106
covered by the index. To learn more about indexes and query optimization, see
107
107
the following MongoDB server manual pages:
108
108
@@ -116,7 +116,7 @@ Create an Index
116
116
~~~~~~~~~~~~~~~
117
117
118
118
To create indexes, call the ``create()`` method on the ``Schema`` facade
119
- in your migration file. Pass ``create()`` the collection name and a callback
119
+ in your migration file. Pass it the collection name and a callback
120
120
method with a ``MongoDB\Laravel\Schema\Blueprint`` parameter. Specify the
121
121
index creation details on the ``Blueprint`` instance.
122
122
@@ -130,7 +130,6 @@ fields:
130
130
Click the :guilabel:`VIEW OUTPUT` button to see the indexes created by running
131
131
the migration, including the default index on the ``_id`` field:
132
132
133
-
134
133
.. io-code-block::
135
134
136
135
.. input:: /includes/schema-builder/flights_migration.php
@@ -139,26 +138,25 @@ the migration, including the default index on the ``_id`` field:
139
138
:start-after: begin create index
140
139
:end-before: end create index
141
140
142
- .. output::
143
- :language: json
144
- :visible: false
145
-
146
- [
147
- { v: 2, key: { _id: 1 }, name: '_id_' },
148
- { v: 2, key: { mission_type: 1 }, name: 'mission_type_1' },
149
- {
150
- v: 2,
151
- key: { launch_location: 1, launch_date: -1 },
152
- name: 'launch_location_1_launch_date_-1'
153
- },
154
- {
155
- v: 2,
156
- key: { mission_id: 1 },
157
- name: 'unique_mission_id_idx',
158
- unique: true
159
- }
160
- ]
141
+ .. output::
142
+ :language: json
143
+ :visible: false
161
144
145
+ [
146
+ { v: 2, key: { _id: 1 }, name: '_id_' },
147
+ { v: 2, key: { mission_type: 1 }, name: 'mission_type_1' },
148
+ {
149
+ v: 2,
150
+ key: { launch_location: 1, launch_date: -1 },
151
+ name: 'launch_location_1_launch_date_-1'
152
+ },
153
+ {
154
+ v: 2,
155
+ key: { mission_id: 1 },
156
+ name: 'unique_mission_id_idx',
157
+ unique: true
158
+ }
159
+ ]
162
160
163
161
Specify Index Options
164
162
~~~~~~~~~~~~~~~~~~~~~
@@ -177,8 +175,8 @@ field:
177
175
.. input:: /includes/schema-builder/passengers_migration.php
178
176
:language: php
179
177
:dedent:
180
- :start-after: begin create index
181
- :end-before: end create index
178
+ :start-after: begin index options
179
+ :end-before: end index options
182
180
183
181
.. output:
184
182
:language: json
@@ -287,7 +285,6 @@ field:
287
285
}
288
286
]
289
287
290
-
291
288
To learn more about these indexes, see :manual:`Index Properties </core/indexes/index-properties/>`
292
289
in the MongoDB server manual.
293
290
@@ -303,12 +300,32 @@ method with a ``MongoDB\Laravel\Schema\Blueprint`` parameter. Specify the
303
300
geospatial index creation details on the ``Blueprint`` instance.
304
301
305
302
The following example migration creates a ``2d`` and ``2dsphere`` geospatial
306
- index on the ``spaceports`` collection:
303
+ index on the ``spaceports`` collection. Click the :guilabel:`VIEW OUTPUT`
304
+ button to see the indexes created by running the migration, including the
305
+ default index on the ``_id`` field:
306
+
307
+ .. io-code-block::
308
+ .. input:: /includes/schema-builder/spaceports_migration.php
309
+ :language: php
310
+ :dedent:
311
+ :start-after: begin create geospatial index
312
+ :end-before: end create geospatial index
313
+
314
+ .. output::
315
+ :language: json
316
+ :visible: false
317
+
318
+ [
319
+ { v: 2, key: { _id: 1 }, name: '_id_' },
320
+ {
321
+ v: 2,
322
+ key: { launchpad_location: '2dsphere' },
323
+ name: 'launchpad_location_2dsphere',
324
+ '2dsphereIndexVersion': 3
325
+ },
326
+ { v: 2, key: { runway_location: '2d' }, name: 'runway_location_2d' }
327
+ ]
307
328
308
- .. literalinclude:: /includes/schema-builder/spaceports_migration.php
309
- :language: php
310
- :start-after: begin create geospatial index
311
- :end-before: end create geospatial index
312
329
313
330
To learn more about geospatial indexes, see
314
331
:manual:`Geospatial Indexes </core/indexes/index-types/index-geospatial/>` in
@@ -317,17 +334,16 @@ the MongoDB Server manual.
317
334
Drop an Index
318
335
~~~~~~~~~~~~~
319
336
320
- You can drop indexes from a collection when you no longer need them.
321
-
322
- When you no longer use an index, you can drop them
337
+ To drop indexes from a collection, call the ``table()`` method on the
338
+ ``Schema`` facade in your migration file. Pass it the table name and a
339
+ callback method with a ``MongoDB\Laravel\Schema\Blueprint`` parameter.
340
+ Call the ``dropIndex()`` method with the index name on the ``Blueprint``
341
+ instance.
323
342
324
- When you drop a collection, MongoDB automatically drops all the indexes
325
- associated with it.
326
-
327
- To drop an index, call the ``table()`` method on the ``Schema`` facade in your
328
- migration file.
343
+ .. note::
329
344
330
- you must reference it by name.
345
+ If you drop a collection, MongoDB automatically drops all the indexes
346
+ associated with it.
331
347
332
348
The following example migration drops an index called ``unique_mission_id_idx``
333
349
from the ``flights`` collection:
0 commit comments