[GODRIVER-869] How to use collection.Watch without the slice/array error? Created: 11/Mar/19 Updated: 11/Sep/19 Resolved: 02/Apr/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | Core API |
| Affects Version/s: | 1.0.0-rc2 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Melle | Assignee: | Kristofer Brandow (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
When using the following code always getting the same error for the 'pipeline' variable that is passed in:
|
| Comments |
| Comment by Melle [ 28/Mar/19 ] | |
|
Thank you! This now works. The code awaits a change in a collection and then continues.
changed codeline from above:
| |
| Comment by Kristofer Brandow (Inactive) [ 20/Mar/19 ] | |
|
The Watch method has not changed, but you can no longer pass in nil as a parameter for any method that takes and empty interface. If you don't have any constraints and want all changes for a collection you can pass in an empty mongo.Pipeline. | |
| Comment by Melle [ 20/Mar/19 ] | |
|
Ok, so that is different from the driver before where the watch just Now for the inventory collection that comes as an example with the driver | |
| Comment by Kristofer Brandow (Inactive) [ 20/Mar/19 ] | |
|
Hi mkoning, --Kris | |
| Comment by Melle [ 20/Mar/19 ] | |
|
In the below test, the line with 'coll.Watch' always returns an err. Below is the test code used that puts the following in the console: The pipeline interface is just there as this has worked with a previous beta release, so probably the use case for a Watch is now different. Is there a good example for how to use the Watch? package sandboxmongodb import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://mongo1:27017,mongo2:27018,mongo3:27019/?replicaSet=my-mongo-set")) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) // db := client.Database("documentation_examples") // we are going to monitor the inventory collection var pipeline interface{} // set up pipeline cur, err := coll.Watch(ctx, pipeline) // Watch can only be done against a MongoDB REPLICA set defer cur.Close(ctx) for ever := false; !ever; { // forever... hmmm... var result bson.M // do something with result if err := cur.Err(); err != nil { log.Fatal(err) }} | |
| Comment by Ian Whalen (Inactive) [ 11/Mar/19 ] | |
|
Hi mkoning - can you please provide the full pipeline you're using that's causing the error? |