[GODRIVER-1113] ListCollectionNames cannot be used Created: 05/Jun/19 Updated: 27/Oct/23 Resolved: 06/Jun/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | Core API |
| Affects Version/s: | 1.0.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Andrew Lee | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
macOS: 10.14.5 |
||
| Attachments: |
|
| Description |
|
I'm not sure if this is something I am doing wrong, but I seem to be unable to use ListCollectionNames (which is should work according to https://godoc.org/go.mongodb.org/mongo-driver/mongo#Database.ListCollectionNames)
Specifically, my code looks like this:
{{ client, err := mongo.Connect(context.Background(), options.Client().ApplyURI("mongodb://127.0.0.1:27017")) client, err := mongo.Connect(context.Background(), options.Client().ApplyURI("mongodb://127.0.0.1:27017")) db := client.Database("thedb") names, _ := db.ListCollectionNames(context.Background(), bson.D{})}} |
| Comments |
| Comment by Andrew Lee [ 06/Jun/19 ] |
|
Thank you |
| Comment by Divjot Arora (Inactive) [ 06/Jun/19 ] |
|
ajlee1000 ListCollectionNames is really a wrapper for Database.ListCollections(options.ListCollections.SetNameOnly(true). It retrieves the cursor from ListCollections, iterates it, and looks for the name field in each document. I'd recommend doing this instead of using RunCommand or RunCommandCursor. The relevant code can be found at https://github.com/mongodb/mongo-go-driver/blob/master/mongo/database.go#L268. |
| Comment by Andrew Lee [ 06/Jun/19 ] |
|
I'm sorry i'm relatively new to Mongo in general. How would you do a `show collections` db.RunCommand interface using bson? |
| Comment by Andrew Lee [ 06/Jun/19 ] |
|
Got it. Thanks |
| Comment by Divjot Arora (Inactive) [ 06/Jun/19 ] |
|
ajlee1000 Thanks for the suggesttion regarding GoDoc. For custom commands, you can use Database.RunCommand and Database.RunCommandCursor to run any command and get back a result/error. |
| Comment by Andrew Lee [ 06/Jun/19 ] |
|
Also, the option to send completely custom commands to MongoDB and return []byte to manually parse would be immensely useful until mongo-go-driver supports all operations |
| Comment by Andrew Lee [ 06/Jun/19 ] |
|
Whats the general timeframe of the next minor update?
Also, might I suggest you guys host your own Godoc server (instead of relying on godoc.org) so that you can have the latest released version docs up rather than what is currently in the master branch (at least until you guys have more reliable documentation for the Go driver)? |
| Comment by Andrew Lee [ 06/Jun/19 ] |
|
O i see. Thanks. |
| Comment by Divjot Arora (Inactive) [ 06/Jun/19 ] |
|
ajlee1000 ListCollectionNames is a new feature, so it was added to the master branch and not backported to the 1.0.x release branch. It will be included in the next minor release (1.1.0). |
| Comment by Andrew Lee [ 05/Jun/19 ] |
|
I have attached a screenshot of the `go build` output as well as attached the test project which caused this (testmongo.zip).
I'm not necessarily going to be on this scrum board, so you can reach me at andrew@voiceit.io. |