我使用 java 的 mongodb 驱动程序编写了类似的内容:
doc = new BasicDBObject("Physicalentity", "Pressure").
append("Sensor", "Tinkerforge").
append("Unit", "Lux").
append("loc", Location).
append("value", pressure).
append("time", time).
append("date", date);
pre_collection.insert(doc);
正如您在上面的代码中看到的,我没有为属性 loc
插入双引号,并且位置定义如下:
String longtitude = "8.9043";
String latitude = "52.0777";
String Location = "["+longtitude+","+latitude+"]";
现在在数据库中它存储为:
{ "_id" : { "$oid" : "5367da1211f6e33b6eba4a9f"} , "Physicalentity" : "Pressure" , "Sensor" : "Tinkerforge" , "Unit" : "Lux" , "loc" : "[8.9043,52.0777]" , "value" : "Air Pressure: 1008.177 mbar" , "time" : "20.36.02" , "date" : "05.05.2014"}
但正如您所看到的,属性 loc 是用双引号存储的 "[8.9043,52.0777]"
但我希望它们在不带双引号的情况下保存,或者如果可能的话,如下所示: “loc:[51,-114]”
我非常感谢您的帮助。
提前非常感谢。
最佳答案
写入该值时,请使用 BasicDBList 作为两个坐标。这将使它们作为数组保存在文档中。
关于java - 修剪在 mongodb java 驱动程序中保存为值的字符串的双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23479560/