[JAVA-1608] Unable to query data after writing to DB in java Created: 05/Jan/15  Updated: 11/Sep/19  Resolved: 05/Jan/15

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Carlos Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

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.



 Comments   
Comment by Jeffrey Yemin [ 05/Jan/15 ]

It's hard to tell what you are doing wrong without more details, but the place to collection that is on the mongodb-user Google group or Stack Overflow. Can you post your question there, and include some more specific information including the actual query that you are running, and a sample document from the collection that you think should be included in the results?

Regards,
Jeff

Generated at Thu Feb 08 08:55:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.