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"),
}
java mongodb
add a comment |
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"),
}
java mongodb
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 say0
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
add a comment |
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"),
}
java mongodb
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
java mongodb
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 say0
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
add a comment |
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 say0
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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