Skip to content

RUST-273: Implement Create indexes #188

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

Closed
wants to merge 7 commits into from
Closed

RUST-273: Implement Create indexes #188

wants to merge 7 commits into from

Conversation

Stargateur
Copy link

@egilsster
Copy link

@Stargateur Hey! Anything I could help with to get this shipped? Interested in this for a project of mine 🙂

@Stargateur
Copy link
Author

It's not urgent for me so I put it on hold, what stop me was index have type and possible option was different for each type example: https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#option-for-collation. I need to take time to think how to implement this properly.

Be aware if this is urgent for you that you can use command to do it manually.

@Stargateur
Copy link
Author

@saghm I must say I have trouble to understand how is design the code, so far I think I'm doing ok but I have trouble to understand how to handle error. A little advice would be very welcome.

@Stargateur
Copy link
Author

So far it's work but write unit test is not my best specially understand how mongodb do it, and I still struggle with handle the error.

@AlekseyKanaev
Copy link

AlekseyKanaev commented Sep 21, 2020

@AlekseyKanaev
Copy link

@saghm could you comment on this pull request?

@saghm
Copy link
Contributor

saghm commented Sep 23, 2020

Hello! You're correct that RUST-273 is the ticket we're using to track the index management work now; we had a couple of tickets covering it, so we wanted to pick one to de-duplicate.

As for the pull request itself, we're happy to merge a working implementation if one is provided, but our team is currently focusing in other areas, and we don't have the bandwidth to provide extensive guidance to the community on how to implement this. We do have plans to implement this functionality at some point in the future, but it's currently not our highest priority due to the fact that using run_command as a workaround exists.

@pooooodles pooooodles added the tracked-in-jira Ticket filed in Mongo's Jira system label Nov 16, 2020
@MMunier
Copy link

MMunier commented May 1, 2021

Is something similar still being worked on?

As for the pull request itself, we're happy to merge a working implementation if one is provided, but our team is currently focusing in other areas, and we don't have the bandwidth to provide extensive guidance to the community on how to implement this. We do have plans to implement this functionality at some point in the future, but it's currently not our highest priority due to the fact that using run_command as a workaround exists.

Since you mention a workaround is there documentation for it? I'm unsure on how I'd use run_command directly. Are there any examples how I'd create an index using run_command?

@Stargateur
Copy link
Author

I didn't have time or/and will to continue this work today, as mongodb is now in 2.0 I expect a lot of change in the code, I did this draft pull request to get help on it if anyone wanted to contribute to create indexes feature. Everyone feel free to copy/use and make your own pull request. This PR only purpose is to share work.

@patrickfreed
Copy link
Contributor

Since you mention a workaround is there documentation for it? I'm unsure on how I'd use run_command directly. Are there any examples how I'd create an index using run_command?

The Database::run_command method allows you to pass in an arbitrary command document that the driver just forwards to the server. Generally we do not reccomend its usage and instead suggest that the various methods on Client / Database / Collection are used instead, but in this case run_command is required since we don't yet have a create_index method.

To create an index via run_command, you'll need to use the createIndexes MongoDB command:

let response = db                      
    .run_command(                      
        doc! {                         
            "createIndexes": "coll",   
            "indexes": [               
                {                      
                    "key": { "x": 1 }, 
                    "name": "my_index",
                    "unique": true     
                },                     
            ]                          
        },                             
        None,                          
    )                                  
    .await?;                           
println!("{}", response);                        

Output:

{ createdCollectionAutomatically: false, numIndexesBefore: 1, numIndexesAfter: 2, ok: 1 }

@pooooodles pooooodles changed the title Rust-458 Implement Create indexes RUST-273: Implement Create indexes May 3, 2021
@isabelatkinson
Copy link
Contributor

Hi @Stargateur, thank you for your work on this pull request! We've recently completed an implementation of index management, so I'm going to close this out. Index management will be included in the 2.0.0 release of the driver which will be out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants