Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-490

Check value type that passed to a sort method

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      Please, take a look at the following code. I think that only int -1 or 1 should be allowed here.

      public static void main(String... args) throws UnknownHostException {
          Mongo m = new Mongo();
          m.setWriteConcern(WriteConcern.SAFE);
          DB db = m.getDB("test");
          db.dropDatabase();
          DBCollection collection = db.getCollection("tmp");
          //random docs insert
          for (int i = 0; i < 10; i++) {
              DBObject object = new BasicDBObject("_id", i);
              object.put("length", (int) (Math.random() * 100));
              collection.insert(object);
          }
       
          print(collection.find().toArray());
          //valid value
          BasicDBObject obj = new BasicDBObject().append("length", 1);
          print(collection.find().sort(obj).toArray());
          //string value
          obj.put("length", "randomString");
          print(collection.find().sort(obj).toArray());
          //object value
          obj.put("length", new BasicDBObject());
          print(collection.find().sort(obj).toArray());
      }
       
      private static void print(List<DBObject> list){
          System.out.println("--size "+list.size());
          for(DBObject o : list){
              System.out.println(o);
          }
          System.out.println("\n");
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            uladzimir_mihura@epam.com Uladzimir Mihura
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: