Unable to query data after writing to DB in java

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      Eclipse (Windows)
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            Unassigned
            Reporter:
            Carlos
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: