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

SlaveOk Query fails with auth error even after logging in

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.8.0
    • Component/s: Cluster Management
    • None

      Copy and pasted from a user's comment on SERVER-6117:

      I tested it on v2.2.0-rc1 and could reproduce the error.
      Java code (using java-driver v2.8.0):

      ArrayList<ServerAddress> servers = new ArrayList<ServerAddress>();
      servers.add(new ServerAddress("s231", 20050));
      servers.add(new ServerAddress("s231", 20051));
      servers.add(new ServerAddress("s231", 20052));
      
      Mongo m = new Mongo(servers);
      
      m.setReadPreference(ReadPreference.SECONDARY);
      final BasicDBObject query = new BasicDBObject();
      final BasicDBObject fields = new BasicDBObject();
      
      query.put("_id", new BasicDBObject("$gte", Integer.valueOf(1)));
      fields.put("_id", Long.valueOf(1));
      
      final DB db = m.getDB("offerStore");
      boolean ok = db.authenticate("user", "pw".toCharArray());
      System.out.println("ok: " + ok);
      final DBCursor c = db.getCollection("offer").find(query, fields).limit(10);
      
      while(c.hasNext()) {
      DBObject offer = c.next();
      System.out.println(offer);
      }
      c.close();
      

      Output after several runs:

      ok: false
      Exception in thread "main" com.mongodb.MongoException: unauthorized db:offerStore ns:offerStore.offer lock type:0 client:192.x.y.z
              at com.mongodb.MongoException.parse(MongoException.java:82)
              at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:317)
              at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:298)
              at com.mongodb.DBCursor._check(DBCursor.java:369)
              at com.mongodb.DBCursor._hasNext(DBCursor.java:492)
              at com.mongodb.DBCursor.hasNext(DBCursor.java:517)
              at de.idealo.offerstore.mongo.TempTest.authenticationTest(TempTest.java:507)
              at de.idealo.offerstore.mongo.TempTest.main(TempTest.java:716)
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            randolph@mongodb.com Randolph Tan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: