[CSHARP-2374] Aggregate Option Comment gives an error when doing an AggregateAsync Created: 04/Sep/18 Updated: 05/Apr/19 Resolved: 11/Sep/18 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Read Operations |
| Affects Version/s: | 2.7.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Rui Ribeiro | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Hello When I do this: var options = new AggregateOptions ;
var match = ... var group = ... var stages = new BsonDocument[] {match, group}; using (var cursor = await collection.AggregateAsync(pipeline, options)) } I am getting an exception when I try to pass a comment as an aggregation option. The error is Command aggregate failed: unrecognized field 'comment'. The stack trace of the exception is at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.ProcessReply(ConnectionId connectionId, ReplyMessage`1 reply)
|
| Comments |
| Comment by Jeffrey Yemin [ 11/Sep/18 ] | |
|
You're welcome. Good luck! | |
| Comment by Rui Ribeiro [ 11/Sep/18 ] | |
|
Ok I see I need add it as part of the condition. Thank you and sorry for my misunderstanding about the property $comment.
| |
| Comment by Jeffrey Yemin [ 11/Sep/18 ] | |
|
I see. MongoDB 3.6 introduces comment as a top level argument to the aggregate command:
That's what the Comment property of AggregateOptions is using. Your example is adding a comment to the filter specified by the $match stage. To do that, add the equivalent $comment field to the "match" BsonDocument in your original example instead of using AggregateOptions.Comment. | |
| Comment by Rui Ribeiro [ 11/Sep/18 ] | |
|
Hi In fact I am using version 3.4. If you to the documentation for the version 3.4, in this page: https://docs.mongodb.com/v3.4/reference/operator/query/comment/ You have this example: db.records.aggregate( [ { $match: { x: { $gt: 0 }, $comment: "Don't allow negative inputs." } }, { $group : { _id: { $mod: [ "$x", 2 ] }, total: { $sum: "$x" }} } ] ) That it works for me when I run directly on console command, but if try to do this in C# using the driver, I get that error. My question is how i can do this using c# mongo driver? | |
| Comment by Jeffrey Yemin [ 10/Sep/18 ] | |
|
Hi rribeiro What version of the MongoDB server are you testing with? The documentation points out that comment support for aggregation was added in MongoDB 3.6. |