MongoDB java driver how to add arrays whith mixed data types

这一生的挚爱 提交于 2019-12-11 07:54:51

问题


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?

来源:https://stackoverflow.com/questions/18868478/mongodb-java-driver-how-to-add-arrays-whith-mixed-data-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!