[英]How to convert InsertOneResult to string using Java mongoClient
I have a method that inserts the record to the MongoDB collection as below我有一种将记录插入 MongoDB 集合的方法,如下所示
public Single<InsertOneResult> create(TagCommand model) {
Tag tag = new Tag();
tag.setName(model.name());
return Single.fromPublisher(this.iRepository.getCollection(ConstantValues.PRODUCT_CATEGORY_COLLECTION_NAME, Tag.class)
.insertOne(tag));
}
Now on the calling method I need to map the inserted id to the other POJO class as shown below.现在在调用方法上,我需要将插入的 ID map 插入到另一个 POJO class 中,如下所示。
The values are shown below值如下所示
The code as blew works for me, just fyi.自爆的代码对我有用,仅供参考。
String id = ((BsonObjectId) insertOneResult.getInsertedId()).getValue().toHexString(); String id = ((BsonObjectId) insertOneResult.getInsertedId()).getValue().toHexString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.