[CSHARP-600] Unrecognized command: $query Created: 11/Oct/12  Updated: 06/Nov/12  Resolved: 19/Oct/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.6
Fix Version/s: 1.6.1

Type: Bug Priority: Major - P3
Reporter: Craig Wilson Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-553 Shardset: Unrecognized command: $read... Closed

 Description   

Thanks for the response

Error message

QueryFailure flag was unrecognized command: $query (response was { "$err" : "unrecognized command: $query", "code" : 13390 }).

Stacktrace

   at MongoDB.Driver.Internal.MongoReplyMessage`1.ReadFrom(BsonBuffer buffer, IBsonSerializationOptions serializationOptions) in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Internal\MongoReplyMessage.cs:line 99
   at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](BsonBinaryReaderSettings readerSettings, IBsonSerializationOptions serializationOptions) in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Internal\MongoConnection.cs:line 475
   at MongoDB.Driver.MongoCursorEnumerator`1.GetReply(MongoConnection connection, MongoRequestMessage message) in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Core\MongoCursorEnumerator.cs:line 296
   at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Core\MongoCursorEnumerator.cs:line 253
   at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Core\MongoCursorEnumerator.cs:line 141
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at MongoDB.Driver.MongoCollection.FindOneAs[TDocument](IMongoQuery query) in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Core\MongoCollection.cs:line 557
   at MongoDB.Driver.MongoCollection`1.FindOne(IMongoQuery query) in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Core\MongoCollection.cs:line 1734
   at MongoDB.Driver.MongoDatabase.RunCommandAs(Type commandResultType, IMongoCommand command) in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Core\MongoDatabase.cs:line 973
   at MongoDB.Driver.MongoDatabase.RunCommandAs[TCommandResult](IMongoCommand command) in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Core\MongoDatabase.cs:line 950
   at MongoDB.Driver.MongoCollection.Aggregate(IEnumerable`1 operations) in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Core\MongoCollection.cs:line 124
   at MongoDB.Driver.MongoCollection.Aggregate(BsonDocument[] operations) in D:\Temp\mongodb-code\mongodb-mongo-csharp-driver-98a0129\Driver\Core\MongoCollection.cs:line 134
   at TopSecretProject;).Service.Internal.AggregateFramework.BaseAggregateFrameworkMongoMentionService.GetAggregateResult(MentionAggregateQuery query, MongoField groupingKey, IDictionary`2 includeAggregateFields, BsonDocument[]& commands, Boolean isTimeSeries) in D:\Projects\TopSecretProject;)\Service\Internal\AggregateFramework\BaseAggregateFrameworkMongoMentionService.cs:line 50
   at TopSecretProject;).Service.Internal.AggregateFramework.AggregateFrameworkMongoMentionService.GetTopItemResults(MentionAggregateQuery query, IDictionary`2 includeAggregateFields) in D:\Projects\TopSecretProject;)\Service\Internal\AggregateFramework\AggregateFrameworkMongoMentionService.cs:line 22

Environment:

MongoDB.Driver: C# 1.6.1.20900
MongoDB.Bson: C# 1.6.1.20899
Mongos: 2.07
- 1 master set (3 shards) 2.07
- 1 slave set (3 shards) 2.2
connectionString: mongodb://mongos-version-2.0.7-ip:port/?readPreference=secondaryPreferred

We could not upgrade master & mongos to 2.2 atm so we have to try this approach as it's mentioned in the doc.
However, if I setup another mongos 2.2, there is not any error but the aggregate result is always empty. I tried to run the same aggregate commands using script against every single shard then it's good. Anyway, this could be another issue.

Cheers



 Comments   
Comment by auto [ 06/Nov/12 ]

Author:

{u'date': u'2012-10-19T00:48:12Z', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-600: Encapsulated the configurable delegate that determines whether a command can be sent to a secondary into a new class called CanCommandBeSentToSecondary.

Conflicts:
DriverUnitTests/Core/CanCommandBeSentToSecondaryTests.cs
DriverUnitTests/MongoDefaultsTests.cs
MongoDB.DriverUnitTests/MongoDefaultsTests.cs
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/dabc6a20d2cf43337762a32f9b99bfba9af6bf4e

Comment by auto [ 06/Nov/12 ]

Author:

{u'date': u'2012-10-18T18:19:08Z', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-600: added support only sending read preference when using one other than primary and secondary preferred or when tags are present.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/760a7193897bffcfd518d2132d09c481983da9a9

Comment by auto [ 06/Nov/12 ]

Author:

{u'date': u'2012-11-05T14:27:27Z', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-600: added secondary ok commands.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/76e9af950ee9c915d3a1312db1d33cda084103d4

Comment by Craig Wilson [ 19/Oct/12 ]

Resolved and pushed to master.

Comment by auto [ 19/Oct/12 ]

Author:

{u'date': u'2012-10-18T17:48:12-07:00', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-600: Encapsulated the configurable delegate that determines whether a command can be sent to a secondary into a new class called CanCommandBeSentToSecondary.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/9eef887695250fe4caa84262ab5dccaab98513c4

Comment by auto [ 19/Oct/12 ]

Author:

{u'date': u'2012-10-18T11:19:08-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-600: added support only sending read preference when using one other than primary and secondary preferred or when tags are present.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/db69b641ae1eaf13d627af7fc826906d9d141926

Comment by auto [ 19/Oct/12 ]

Author:

{u'date': u'2012-10-18T08:56:10-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-600: added secondary ok commands.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/84e6f612625d2cdad9dd9da94058da27f22e74e2

Comment by Craig Wilson [ 16/Oct/12 ]

I was able to reproduce this with 1 mongos (2.0.7), 1 config server (2.2.0), and 1 mongod shard (2.2.0). This works when the mongos is 2.2.0. Below is the code:

          
var server = MongoServer.Create("mongodb://localhost:3000");
var db = server.GetDatabase("agg_test");
var collection = db.GetCollection("pipe");
 
var result = collection.Aggregate(new BsonDocument { { "$project", new BsonDocument("name", 1) } });

The above produces the following json sent to the server:
"{ "$query" : { "aggregate" : "pipe", "pipeline" : [{ "$project" :

{ "name" : 1 }

}] }, "$readPreference" :

{ "mode" : "primary" }

}"

I think the ultimate issue here is the attempt to use aggregation framework through a mongos < 2.2.0. The error message reported indicates that mongos doesn't like the $query parameter that exists because we need to pass the additional $readpreference parameter as well. Just as a test, I got rid of the wrapped query part so it wouldn't send the read preference. Below is the query sent:
"{ "aggregate\" : "pipe", "pipeline" : [{ "$project" :

{ "name" : 1 }

}] }"

Of course this didn't work, because mongos 2.0.7 doesn't know about the aggregate command, so it didn't know what to do with it.

I tested other commands, like collstats, and these worked just fine, so I believe the issue is solely with the use of the aggregation command in pre 2.2.0 mongos.

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