MongoDB java driver how to add arrays whith mixed

2019-08-14 21:23发布

问题:

I am trouble because I want to increment a date object in 1 hour, with the java driver, this is:

{"tDate":{$add: ["$tDate", 3600*1000]}

making, wont work because mongoDB expects a number and receives a string

String [] date_add_array =  {"$t_tDate", String.valueOf(3600*1000) };
BasicDBObject query_component = new BasicDBObject("tDate", new BasicDBObject("$add", date_add_array))

>exception: $add only supports numeric or date types, not String

Using a BasicDBList object list won't work, because I don't want an object inside the array. This would be (and is not what I want or need):

 {"tDate":{$add: [{"$tDate", 3600*1000}]}

What is the work around? How can I feed MongoDB with an array of mixed data types?