I had updated the mongoDB using $setOnInsert. It is working in 2.4 version of mongoDB but it is throwing error in 2.6 version.
Following are the code
BasicDBObject update = new BasicDBObject();
BasicDBObject visits = new BasicDBObject();
visits.append("request", getRequestInfo(input));//Some documents
update.append("$setOnInsert", {}).append("$push", visits);
collection.update(searchQuery, update, true, false);
Error
java.lang.RuntimeException: com.mongodb.MongoException: '$setOnInsert' is empty. You must specify a field like so: {$mod: {: ...}}
Note: I had two mongoDB servers. It is working in one server. It is giving above issue in another. Only difference is version.
After Updating the document in 2.4.8
{
"_id" : ObjectId("536113766a47069648b4695d"),
"request" : [
{
"currentVisit" : "1398254762",
"lastVisit" : "1398254762"
}
],
"session" : "1",
"uuid" : "113862726056042"
}
Any problem with the version.
Any suggestion will be grateful.