MongoDb Java API failing to update











up vote
0
down vote

favorite












I am trying to update MongoDB records based on two Search parameters which are Long values. I am using the below code for the update.But I am not able to figure out the mistakes which is making the updates failed. Appreciate any help from the experts.



try {

//Code to get the connection to MongoDb
//code to get the Collection

long newupdateValue=-101L;

BasicDBObject updateQuery = new BasicDBObject().append("$set", new BasicDBObject().append("orderId", newupdateValue));


Configurer queryConfig = Configurer.getInstance(queriesFile);

String Ids= // List of Ids



long OrderId= //Get the Order Id

for (String id: Ids) {

long idInLong = Long.parseLong(id);

BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("orderId", OrderId);
searchQuery.put("id", idInLong );

WriteResult wr = collection.updateMulti(searchQuery, updateQuery);
System.out.println(wr);

}

}

catch(Exception e) {
e.printStackTrace();
}

finally {
MongoDbConnectionManager.closeMongoDbConnection(mongoClient);

}


MongoDb field Details are:



{



"orderId" : NumberLong("99"),

"id" : NumberLong("1234"),


}










share|improve this question


















  • 1




    What does the write result say? It will not only tell you the number of updates but also the number of matches. If the matches say 0 then the query criteria is wrong.
    – Neil Lunn
    Nov 21 at 6:00










  • Yes I am getting zero.I have checked in the database for the validity of my searchquery values.They are present.
    – Bindumalini KK
    Nov 21 at 8:34










  • Well your Java code does not think they are valid, so something is off. Either the query parameters are not what you think they are, or you are pointing at the wrong collection. Time to do some logging and checking.
    – Neil Lunn
    Nov 21 at 8:39










  • I am hitting the right collection. Is there any mistake in setting the searchQuery and UpdateQuery?
    – Bindumalini KK
    Nov 21 at 8:47















up vote
0
down vote

favorite












I am trying to update MongoDB records based on two Search parameters which are Long values. I am using the below code for the update.But I am not able to figure out the mistakes which is making the updates failed. Appreciate any help from the experts.



try {

//Code to get the connection to MongoDb
//code to get the Collection

long newupdateValue=-101L;

BasicDBObject updateQuery = new BasicDBObject().append("$set", new BasicDBObject().append("orderId", newupdateValue));


Configurer queryConfig = Configurer.getInstance(queriesFile);

String Ids= // List of Ids



long OrderId= //Get the Order Id

for (String id: Ids) {

long idInLong = Long.parseLong(id);

BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("orderId", OrderId);
searchQuery.put("id", idInLong );

WriteResult wr = collection.updateMulti(searchQuery, updateQuery);
System.out.println(wr);

}

}

catch(Exception e) {
e.printStackTrace();
}

finally {
MongoDbConnectionManager.closeMongoDbConnection(mongoClient);

}


MongoDb field Details are:



{



"orderId" : NumberLong("99"),

"id" : NumberLong("1234"),


}










share|improve this question


















  • 1




    What does the write result say? It will not only tell you the number of updates but also the number of matches. If the matches say 0 then the query criteria is wrong.
    – Neil Lunn
    Nov 21 at 6:00










  • Yes I am getting zero.I have checked in the database for the validity of my searchquery values.They are present.
    – Bindumalini KK
    Nov 21 at 8:34










  • Well your Java code does not think they are valid, so something is off. Either the query parameters are not what you think they are, or you are pointing at the wrong collection. Time to do some logging and checking.
    – Neil Lunn
    Nov 21 at 8:39










  • I am hitting the right collection. Is there any mistake in setting the searchQuery and UpdateQuery?
    – Bindumalini KK
    Nov 21 at 8:47













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to update MongoDB records based on two Search parameters which are Long values. I am using the below code for the update.But I am not able to figure out the mistakes which is making the updates failed. Appreciate any help from the experts.



try {

//Code to get the connection to MongoDb
//code to get the Collection

long newupdateValue=-101L;

BasicDBObject updateQuery = new BasicDBObject().append("$set", new BasicDBObject().append("orderId", newupdateValue));


Configurer queryConfig = Configurer.getInstance(queriesFile);

String Ids= // List of Ids



long OrderId= //Get the Order Id

for (String id: Ids) {

long idInLong = Long.parseLong(id);

BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("orderId", OrderId);
searchQuery.put("id", idInLong );

WriteResult wr = collection.updateMulti(searchQuery, updateQuery);
System.out.println(wr);

}

}

catch(Exception e) {
e.printStackTrace();
}

finally {
MongoDbConnectionManager.closeMongoDbConnection(mongoClient);

}


MongoDb field Details are:



{



"orderId" : NumberLong("99"),

"id" : NumberLong("1234"),


}










share|improve this question













I am trying to update MongoDB records based on two Search parameters which are Long values. I am using the below code for the update.But I am not able to figure out the mistakes which is making the updates failed. Appreciate any help from the experts.



try {

//Code to get the connection to MongoDb
//code to get the Collection

long newupdateValue=-101L;

BasicDBObject updateQuery = new BasicDBObject().append("$set", new BasicDBObject().append("orderId", newupdateValue));


Configurer queryConfig = Configurer.getInstance(queriesFile);

String Ids= // List of Ids



long OrderId= //Get the Order Id

for (String id: Ids) {

long idInLong = Long.parseLong(id);

BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("orderId", OrderId);
searchQuery.put("id", idInLong );

WriteResult wr = collection.updateMulti(searchQuery, updateQuery);
System.out.println(wr);

}

}

catch(Exception e) {
e.printStackTrace();
}

finally {
MongoDbConnectionManager.closeMongoDbConnection(mongoClient);

}


MongoDb field Details are:



{



"orderId" : NumberLong("99"),

"id" : NumberLong("1234"),


}







java mongodb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 5:55









Bindumalini KK

4121516




4121516








  • 1




    What does the write result say? It will not only tell you the number of updates but also the number of matches. If the matches say 0 then the query criteria is wrong.
    – Neil Lunn
    Nov 21 at 6:00










  • Yes I am getting zero.I have checked in the database for the validity of my searchquery values.They are present.
    – Bindumalini KK
    Nov 21 at 8:34










  • Well your Java code does not think they are valid, so something is off. Either the query parameters are not what you think they are, or you are pointing at the wrong collection. Time to do some logging and checking.
    – Neil Lunn
    Nov 21 at 8:39










  • I am hitting the right collection. Is there any mistake in setting the searchQuery and UpdateQuery?
    – Bindumalini KK
    Nov 21 at 8:47














  • 1




    What does the write result say? It will not only tell you the number of updates but also the number of matches. If the matches say 0 then the query criteria is wrong.
    – Neil Lunn
    Nov 21 at 6:00










  • Yes I am getting zero.I have checked in the database for the validity of my searchquery values.They are present.
    – Bindumalini KK
    Nov 21 at 8:34










  • Well your Java code does not think they are valid, so something is off. Either the query parameters are not what you think they are, or you are pointing at the wrong collection. Time to do some logging and checking.
    – Neil Lunn
    Nov 21 at 8:39










  • I am hitting the right collection. Is there any mistake in setting the searchQuery and UpdateQuery?
    – Bindumalini KK
    Nov 21 at 8:47








1




1




What does the write result say? It will not only tell you the number of updates but also the number of matches. If the matches say 0 then the query criteria is wrong.
– Neil Lunn
Nov 21 at 6:00




What does the write result say? It will not only tell you the number of updates but also the number of matches. If the matches say 0 then the query criteria is wrong.
– Neil Lunn
Nov 21 at 6:00












Yes I am getting zero.I have checked in the database for the validity of my searchquery values.They are present.
– Bindumalini KK
Nov 21 at 8:34




Yes I am getting zero.I have checked in the database for the validity of my searchquery values.They are present.
– Bindumalini KK
Nov 21 at 8:34












Well your Java code does not think they are valid, so something is off. Either the query parameters are not what you think they are, or you are pointing at the wrong collection. Time to do some logging and checking.
– Neil Lunn
Nov 21 at 8:39




Well your Java code does not think they are valid, so something is off. Either the query parameters are not what you think they are, or you are pointing at the wrong collection. Time to do some logging and checking.
– Neil Lunn
Nov 21 at 8:39












I am hitting the right collection. Is there any mistake in setting the searchQuery and UpdateQuery?
– Bindumalini KK
Nov 21 at 8:47




I am hitting the right collection. Is there any mistake in setting the searchQuery and UpdateQuery?
– Bindumalini KK
Nov 21 at 8:47

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406027%2fmongodb-java-api-failing-to-update%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406027%2fmongodb-java-api-failing-to-update%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...