1

I'm using the MongoDB Java driver, and can't seem to get a query to work. I have a collection named "Questions", which has entries that look like:

{
    "question"  : "how are you",
    "category"  : "personal",
    "processed" : false,
    "training"  : true
}

When running the Mongo command line client, the query

db.questions.find()

or

db.questions.find({"processed" : false, "training" : true})

results are returned as expected; however, my java code does the following:

DBObject queryObj = new BasicDBObject();
queryObj.put("processed", false);
queryObj.put("training",   isTrain);

DBObject updateObj = new BasicDBObject();
queryObj.put("processed", true);

DBCursor cursor = mongoCollection.find(queryObj).limit(NUM_TO_LOAD);
mongoCollection.update(queryObj, updateObj);

and the cursor that is returned to me is empty/the update doesn't make any changes. If I remove the queryObj argument from the call to find, results are once again returned as expected. Am I doing something wrong here?

Thanks,
Chris Covert

1 Answer 1

2

looks like, you used the wrong variable on line 6. Shouldn't it be updateObj, instead of queryObj?

Hope isTrain is a boolean, and got correctly initiated with a value (true/false).

Sign up to request clarification or add additional context in comments.

1 Comment

facepalm. You wouldn't believe how long I've looked at that code for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.