JsonObject primaryFilter = new JsonObject();
primaryFilter.put("_id", new org.bson.types.ObjectId.ObjectId("55dc66a5c483983722efb8b1"));
at runtime I'm getting :
java.lang.IllegalStateException: Illegal type in JsonObject: class org.bson.types.ObjectId
at io.vertx.core.json.Json.checkAndCopy(Json.java:115)
at io.vertx.core.json.JsonObject.put(JsonObject.java:591)
at com.ibm.ic.webui.verticle.DataProviderVerticle.handleRequestData(DataProviderVerticle.java:59)
at com.ibm.ic.webui.verticle.DataProviderVerticle$$Lambda$12/1019412361.handle(Unknown Source)
at io.vertx.core.eventbus.impl.EventBusImpl$HandlerRegistration.handle(EventBusImpl.java:1108)
at io.vertx.core.eventbus.impl.EventBusImpl.lambda$doReceive$189(EventBusImpl.java:755)
at io.vertx.core.eventbus.impl.EventBusImpl$$Lambda$92/383514363.handle(Unknown Source)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$15(ContextImpl.java:314)
at io.vertx.core.impl.ContextImpl$$Lambda$7/79290250.run(Unknown Source)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:357)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
at java.lang.Thread.run(Thread.java:745)
So io.vertx.core.json.JsonObject cant take a org.bson.types.ObjectId to define a mongodb Objectid, thats understood.
How can I then query for a specific document _id ?
the doc in my collection looks like this:
{
"_id" : ObjectId("55dcd02c158c1d3a5fa423f2"),
"serial" : "xyz",
"firstname" : "Hans",
"lastname" : "Tester",
"email" : "xyz",
}
I also tried the following:
mongo.find(collection, new JsonObject("{\"_id\":\"55dcd02c158c1d3a5fa423f2\"}, lookup -> {
}
this gives me an empty resultset. it cant really match this string to the objectid in mongodb
Thanks for any help
useObjectId to true when initializing MongoClient.
However that still doesnt work for me to query by documentid via
mongo.find(collection, new JsonObject("{\"_id\":\"55dcd02c158c1d3a5fa423f2\"}"), lookup -> {
it still doesnt find anything...
any help is highly appreciated
mongoconfig.put("useObjectId", "true");
new JsonObject().put("_id", new ObjectId().toHexString());
new JsonObject().put("someoid", new JsonObject().put("$oid", new ObjectId().toHexString()));mongoConfig.put("useObjectId", true);
JsonObject primaryFilter = new JsonObject();
primaryFilter.put("_id", some_previously_saved_hex_string);JsonObject filter = new JsonObject().put("_id", new JsonObject().put("$oid", "55dcd02c158c1d3a5fa423f2"));
mongo.find(collectionName, filter, lookup -> {