Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-27492

Support $natural sorts on views

    XMLWordPrintable

    Details

      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

            Activity

              People

              Assignee:
              backlog-server-query Backlog - Query Team (Inactive)
              Reporter:
              NathanFan Nathan Fan [X]
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: