0 | I am struggling to fix this problem where I have to get the inserted _id field for the mongodb async insertOne function. Can some one help or I have to get rid of the Async driver completely as there is no way ? following this tutoraial http://mongodb.github.io/mongo-java-driver/3.0/driver-async/getting-started/quick-tour/ .. Note : The document is successfully inserted to mongodb with the below call but there is no way that I can get the _id from this api.
|
final Document userMessage = new Document();
// add fields to userMessage
collection.insertOne(userMessage, new SingleResultCallback<Void>() {
@Override
public void onResult(final Void result, final Throwable t) {
// The _id value will be available in userMessage itself
System.out.println(userMessage.get("_id"));
}
});
Let me know if that works for you.
Regards,
Jeff