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

Unable to query data after writing to DB in java

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • Eclipse (Windows)

    Description

      I am using java to write to a MongoDB the following way:
      (java code):
      MongoClient mongo = new MongoClient("localhost", 27017);
      DB db = mongo.getDB("testdb");
      DBCollection table = db.getCollection("myCollection");
      BasicDBObject document = new BasicDBObject();

      document.put("someKey", someValue);
      ...
      table.insert(document);

      It writes to the DB fine, however I am UNABLE TO QUERY out the results.
      The only way i can query the results is by going into mongo and running the following command:

      db.myCollection.find().forEach(printjson);

      The command above will show ALL the results for that particular table in JSON format (As its expected), however if run the following command:

      db.myCollection.find(

      {someKey : "someValue"}

      , {_id: 0, someKey : 1});

      I get no results, or at least none written from my Java code, if I write entries any other way, they do query out normally.

      I am wondering if this is a common problem, and if there's a work around for it.

      Note: I also noticed that the entries written from my Java code are indented a little further than the entries NOT written from the Java code.

      Attachments

        Activity

          People

            Unassigned Unassigned
            cjrodriguez1 Carlos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: