|
36 | 36 |
|
37 | 37 | # Create Search Index
|
38 | 38 | # start-create-search-index
|
39 |
| -index_definition = { |
40 |
| - name: '<index name>', |
41 |
| - definition: { |
42 |
| - mappings: { |
43 |
| - dynamic: false, |
44 |
| - fields: { <field name>: {type: '<field type>'} } |
| 39 | +index_definition = { |
| 40 | + mappings: { |
| 41 | + dynamic: false, |
| 42 | + fields: { |
| 43 | + <field name>: {type: '<field type>'} |
45 | 44 | }
|
46 | 45 | }
|
47 | 46 | }
|
48 |
| -collection.database.command( |
49 |
| - createSearchIndexes: '<collection name>', |
50 |
| - indexes: [index_definition] |
51 |
| -) |
| 47 | +collection.search_indexes.create_one(index_definition, name: '<index name>') |
52 | 48 | # end-create-search-index
|
53 | 49 |
|
54 | 50 | # List Search Indexes
|
55 | 51 | # start-list-search-indexes
|
56 |
| -collection.database.command(listSearchIndexes: '<collection name>') |
| 52 | +puts collection.search_indexes.collect(&:to_json) |
57 | 53 | # end-list-search-indexes
|
58 | 54 |
|
59 | 55 | # Update Search Indexes
|
60 | 56 | #start-update-search-indexes
|
61 | 57 | updated_definition = {
|
62 | 58 | mappings: {
|
63 | 59 | dynamic: false,
|
64 |
| - fields: { <updated field name>: { type: '<field type>' } } |
| 60 | + fields: { <updated field name>: { type: '<updated field type>' } } |
65 | 61 | }
|
66 | 62 | }
|
67 |
| -collection.database.command( |
68 |
| - updateSearchIndex: '<collection name>', |
69 |
| - name: '<index name>', |
70 |
| - definition: updated_definition |
71 |
| -) |
| 63 | + |
| 64 | +collection.search_indexes.update_one(updated_definition, name: '<index name>') |
72 | 65 | #end-update-search-indexes
|
73 | 66 |
|
74 | 67 | # Delete Search Index
|
75 | 68 | # start-drop-search-index
|
76 |
| -collection.database.command( |
77 |
| - dropSearchIndex: '<collection name>', |
78 |
| - name: '<index name>' |
79 |
| -) |
| 69 | +collection.search_indexes.drop_one(name: '<index name>') |
80 | 70 | # end-drop-search-index
|
81 | 71 |
|
82 | 72 | # Text Index
|
|
0 commit comments