[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

{ AllowDiskUse = true, Comment = "TESTE" }

;

 

var match = ...

var group = ...

var stages = new BsonDocument[] {match, group};
var pipeline = PipelineDefinition<BsonDocument,BsonDocument>.Create(stages);

using (var cursor = await collection.AggregateAsync(pipeline, options))
{
    while (await cursor.MoveNextAsync())
   

{        }

}

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)
at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.<ExecuteAsync>d__14.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Servers.Server.ServerChannel.<ExecuteProtocolAsync>d__29`1.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Operations.CommandOperationBase`1.<ExecuteProtocolAsync>d__28.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Operations.ReadCommandOperation`1.<ExecuteAsync>d__2.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Operations.AggregateOperation`1.<ExecuteAsync>d__55.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.OperationExecutor.<ExecuteReadOperationAsync>d__3`1.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.MongoCollectionImpl`1.<ExecuteReadOperationAsync>d__93`1.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.MongoCollectionImpl`1.<AggregateAsync>d__22`1.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.MongoCollectionImpl`1.<UsingImplicitSessionAsync>d__101`1.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at abc.Teste.<GetTeste>d__54.MoveNext() in 

 



 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:

db.test.aggregate([], {comment : "this is my comment"})

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.

Generated at Wed Feb 07 21:42:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.