Spring Data MongoDB:BigInteger到ObjectId的转换 [英] Spring Data MongoDB: BigInteger to ObjectId conversion

查看:98
本文介绍了Spring Data MongoDB:BigInteger到ObjectId的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Spring Data MongoDB进行更新查询时遇到问题。我将一些对象的_id检索为BigInteger值。然后我想进行以下查询:

I have a problem with update query using Spring Data MongoDB. I retrieve some object's _id as BigInteger value. Then I want to make following query:

Query query = new Query(Criteria.where("_id").is(id));
Update update = new Update();
update.set("version",version);
mongoOperations.updateFirst(query, update, Audit.class);

查询部分无法匹配任何文档,因为传递给的id值为() 必须以某种方式转换为ObjectId。我找不到关于这种转换的任何文档。将不胜感激任何帮助。

Query part fails to match any documents since id value passed to is() somehow must be converted to ObjectId. I can't find any documentation on this kind of conversion. Will appreciate any help.

ps:SpringData Mongodb版本1.2

p.s.: SpringData Mongodb version 1.2

推荐答案

你可以转换它也可以手动:

You can convert it also manually:

ObjectId convertedId = new ObjectId(bigInteger.toString(16));
Query query = new Query(Criteria.where("_id").is(convertedId));

这篇关于Spring Data MongoDB:BigInteger到ObjectId的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆