I'm getting this error: Document field names can't start with '$' (Bad Key: '$inc')
with this code:
private static void countryInc(String user_id, String country, BasicDBObject doc, DBCollection dBcollection, Integer count ) throws IOException {
DBObject fromDBobject = new BasicDBObject();
DBObject countryDBobject = new BasicDBObject();
countryDBobject.put(country, count);
fromDBobject.put("user_id", user_id);
fromDBobject.put("countries", countryDBobject);
DBObject toDBobject = new BasicDBObject();
DBObject ccDBObject = new BasicDBObject(country, 1);
DBObject incdbobject = new BasicDBObject("$inc", ccDBObject);
toDBobject.put("user_id", user_id);
toDBobject.put("countries", incdbobject);
dBcollection.update(fromDBobject, toDBobject);
}
this is a sample of what my db looks like:
{
"_id" : {
"$oid" : "53b56ccb1ac175a446cf244f"
},
"user_id" : "7778",
"countries": { "JA" : 1}
}
{
"_id" : {
"$oid" : "53b56ccb1ac175a446cf2450"
},
"user_id" : "4657",
"countries" : { "TU" : 1}
}
{
"_id" : {
"$oid" : "53b56ccb1ac175a446cf2451"
},
"user_id" : "5918",
"countries" : { "BR" : 1}
}
I'm at a loss as to why this won't increment the count for each country every time that a user_id is seen.