Details
-
Improvement
-
Resolution: Won't Fix
-
Major - P3
-
None
-
3.4.0
-
Server 3.4.0
-
Query
Description
In the code I tried to treat Views the same as collections. We applied .sort({$natural:1}) to all the queries. For normal collections the driver worked as before, but the sort failed on Views retrieval.
The example shown below:
MongoCollection collection = client.getDatabase("test").getCollection("managementFeedback"); |
FindIterable cursor = collection.find()
|
.sort(new BsonDocument("$natural", new BsonInt32(1))).limit(2); |
MongoCursor<BsonDocument> document = cursor.iterator();
|
This returned:
Exception in thread "main" com.mongodb.MongoQueryException: Query failed with error code 16410 and error message 'FieldPath field names may not start with '$'.' on server 192.168.203.167:27017 |
at com.mongodb.operation.FindOperation$1.call(FindOperation.java:521) |
at com.mongodb.operation.FindOperation$1.call(FindOperation.java:510) |
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:431) |
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:404) |
at com.mongodb.operation.FindOperation.execute(FindOperation.java:510) |
at com.mongodb.operation.FindOperation.execute(FindOperation.java:81) |
at com.mongodb.Mongo.execute(Mongo.java:836) |
at com.mongodb.Mongo$2.execute(Mongo.java:823) |
at com.mongodb.OperationIterable.iterator(OperationIterable.java:47) |
at com.mongodb.FindIterableImpl.iterator(FindIterableImpl.java:151) |
at test.Test.main(Test.java:55) |
Is it the way I dealt with views wrongly?
If I should treat views specially (views are not sortable or already sorted), do I have a way to figure out if the collection is a collection or a view other than accessing the system.views collection?
P.S. mongoclient / command line (mongo) having the same problem as Java driver:
Error: error: {
|
"ok" : 0,
|
"errmsg" : "FieldPath field names may not start with '$'.",
|
"code" : 16410,
|
"codeName" : "Location16410"
|
}
|
Thanks for helping guys.
Attachments
Issue Links
- is related to
-
SERVER-7944 add index hint support for operations that read indexes
-
- Closed
-
- related to
-
SERVER-26960 Consider improving error message when attempting $natural sort on a view
-
- Closed
-