我有两个集合,一个引用了另一个由国外的ObjectId。我正在尝试对这两个集合执行$lookup。问题是外来的ObjectId被保存为以下格式的文档:
"testId" : { "timestamp" : 1469105907, "machineIdentifier" : 8036392, "processIdentifier" : 7899, "counter" : 12372063, "timeSecond" : 1469105907, "time" : NumberLong("1469105907000"), "date" : NumberLong("1469105907000") }
而上面引用的ObjectId格式如下:
ObjectId("5790c6437aa0281e0f534729")如何将外部ObjecId保存为所引用的sae格式?
我用的是java驱动和mongo 3.2.0!保存文档,如下所示:
Test at = new Test();
at.setForeignId(new ObjectId("5790c6437aa0281e0f534729"));发布于 2016-07-23 22:45:48
对不起!问题出在文档插入中。我使用的是一个以这种方式呈现ObjectId的映射器对象。!不要使用这个:
org.codehaus.jackson.map.ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString( POJO_OBJECT );
Document doc = Document.parse(jsonString);我必须通过如下方式创建一个文档来重新配置整个插入过程:
Document doc = new Document();
doc.append("_id", POJO_OBJECT.theObjectId);
doc.append("foreign", POJO_OBJECT.theForeignId);
doc.append("objectOne", POJO_OBJECT.objectOne);
doc.append("objectTwo", POJO_OBJECT.objectTwo);
...然后使用此文档进行插入!希望这能拯救一些headache
https://stackoverflow.com/questions/38505261
复制相似问题