[GODRIVER-3072] wrong doc for go driver in indexing Created: 15/Dec/23 Updated: 23/Jan/24 Resolved: 23/Jan/24 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | 1.13.1 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Alireza Arzehgar | Assignee: | Preston Vasquez |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Description |
|
I'm not an expert. But I think we have some problems on documentions of go driver. I will be glad if I can contribute to solving these problems.
Anyway this is explanation of a problem:
I read this document page for using indexes.
Code examples have error. for example see following code: indexModel := mongo.IndexModel{ fmt.Println("Name of Index Created: " + name) ```` First bug of this code is that in line 2 we should write a comma. This code wont compile.
Next problem is that following code will throw error: ```go func main() { options.Client().ApplyURI("mongodb://127.0.0.1:27017"), database := client.Database("appdb") indexModel := mongo.IndexModel{ fmt.Println("Name of Index Created: " + name) ```
This code will print following error: ``` 2023/12/15 23:18:50 cannot marshal type bson.D to a BSON Document: WriteArray can only write a Array while positioned on a Element or Value but is positioned on a TopLevel ``` If I change IndexModel.keys type to []string or bson.M, code will work correctly. Correct code: ```go indexModel := mongo.IndexModel { Keys: bson.M\{"username": 1}, ```
Correct code: ``` indexModel := mongo.IndexModel { Keys: []string\{"username"}, ``` |
| Comments |
| Comment by PM Bot [ 23/Jan/24 ] | |||||||||||||||||||||||||||||||||||||||
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to reopen this ticket if you're still experiencing the issue, and add a comment if you're able to provide more information. | |||||||||||||||||||||||||||||||||||||||
| Comment by PM Bot [ 16/Jan/24 ] | |||||||||||||||||||||||||||||||||||||||
|
Hi alirezaarzehgar82@gmail.com! If this is still an issue for you, please open Jira to review the latest status and provide your feedback. Thanks! | |||||||||||||||||||||||||||||||||||||||
| Comment by Preston Vasquez [ 09/Jan/24 ] | |||||||||||||||||||||||||||||||||||||||
|
Hi alirezaarzehgar82@gmail.com , you are correct there appears to be a typo in the documentation. Thank you for pointing this out, I have created DOCS-16571 to address this issue. The code you've provided compiles and runs without error on 1.13.1:
Could you give us more information on your use case? Note that the following will not run successfully:
And results in the following error:
As documented by the Go Driver, Keys must be an order-preserving type, such as bson.D. While bson.M does not error like a slice would, it represents incorrect usage and will result in unexpected behavior. | |||||||||||||||||||||||||||||||||||||||
| Comment by PM Bot [ 15/Dec/23 ] | |||||||||||||||||||||||||||||||||||||||
|
Hi alirezaarzehgar82@gmail.com, thank you for reporting this issue! The team will look into it and get back to you soon. |