-
Notifications
You must be signed in to change notification settings - Fork 29
DOCSP-45202 Index Overview #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lindseymoore
merged 9 commits into
mongodb:standardization
from
lindseymoore:DOCSP-45202
Jan 16, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e8badd1
DOCSP-45202 Index Overview
lindseymoore 38ba81a
edits
lindseymoore dbe21b3
fix ref
lindseymoore 9116c92
atlas search updates
lindseymoore a6c714d
small fix
lindseymoore a18ad37
add api section, edit atlas search examples
lindseymoore 86c6189
edits
lindseymoore bdbf28e
Merge branch 'standardization' of github.com:mongodb/docs-ruby into D…
lindseymoore e10fed3
tech review
lindseymoore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
require 'mongo' | ||
|
||
# Replace the placeholders with your credentials | ||
uri = "<connection string>" | ||
|
||
# Sets the server_api field of the options object to Stable API version 1 | ||
options = { server_api: { version: '1' }} | ||
|
||
# Creates a new client and connects to the server | ||
client = Mongo::Client.new(uri, options) | ||
|
||
database = client.use('<database name>') | ||
collection = database[:<collection name>] | ||
|
||
# Single Field | ||
# start-index-single | ||
collection.indexes.create_one({ <field name>: 1 }) | ||
# end-index-single | ||
|
||
# Compound | ||
# start-index-compound | ||
collection.indexes.create_one({ <field name 1>: -1, <field name 2>: 1 }) | ||
# end-index-compound | ||
|
||
# Multikey | ||
# start-index-multikey | ||
collection.indexes.create_one({ <field name>: 1 }) | ||
# end-index-multikey | ||
|
||
# Geospatial | ||
# start-index-geospatial | ||
collection.indexes.create_one({ <GeoJSON field name>: '2dsphere' }) | ||
# end-index-geospatial | ||
|
||
# Atlas Search | ||
|
||
# Create Search Index | ||
# start-create-search-index | ||
index_definition = { | ||
mappings: { | ||
dynamic: false, | ||
fields: { | ||
<field name>: { type: '<field type>' } | ||
} | ||
} | ||
} | ||
collection.search_indexes.create_one(index_definition, name: '<index name>') | ||
# end-create-search-index | ||
|
||
# List Search Indexes | ||
# start-list-search-indexes | ||
puts collection.search_indexes.collect(&:to_json) | ||
# end-list-search-indexes | ||
|
||
# Update Search Indexes | ||
#start-update-search-indexes | ||
updated_definition = { | ||
mappings: { | ||
dynamic: false, | ||
fields: { <updated field name>: { type: '<updated field type>' } } | ||
} | ||
} | ||
|
||
collection.search_indexes.update_one(updated_definition, name: '<index name>') | ||
#end-update-search-indexes | ||
|
||
# Delete Search Index | ||
# start-drop-search-index | ||
collection.search_indexes.drop_one(name: '<index name>') | ||
# end-drop-search-index | ||
|
||
# Text Index | ||
# start-text | ||
collection.indexes.create_one({ <field name>: 'text' }) | ||
# end-text | ||
|
||
# Create Many | ||
# start-index-create-many | ||
collection.indexes.create_many([ | ||
{ key: { <field name 1>: 1 } }, | ||
{ key: { <field name 2>: -1 } }, | ||
]) | ||
# end-index-create-many | ||
|
||
# Delete an Index | ||
# start-drop-single-index | ||
collection.indexes.drop_one( '<index name>' ) | ||
# end-drop-single-index | ||
|
||
# Drops all indexes in the collection. | ||
# start-drop-all-index | ||
collection.indexes.drop_all | ||
# end-drop-all-index | ||
|
||
# List an Index | ||
# start-list-indexes | ||
puts collection.indexes.collect(&:to_json) | ||
# end-list-indexes | ||
|
||
client.close |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'mongo' | ||
|
||
# Replace the placeholders with your credentials | ||
uri = "<connection string>" | ||
|
||
# Sets the server_api field of the options object to Stable API version 1 | ||
options = { server_api: { version: "1" }} | ||
|
||
# Creates a new client and connect to the server | ||
client = Mongo::Client.new(uri, options) | ||
|
||
database = client.use('<database name>') | ||
collection = database[:<collection name>] | ||
|
||
# Start example code here | ||
|
||
# End example code here | ||
|
||
client.close |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.