5

Spring Data MongoDB を使用した更新クエリに問題があります。オブジェクトの _id を BigInteger 値として取得します。次に、次のクエリを作成します。

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

何らかの形で渡された ID 値is()を ObjectId に変換する必要があるため、クエリ部分はどのドキュメントとも一致しません。この種の変換に関するドキュメントは見つかりません。どんな助けにも感謝します。

ps: SpringData Mongodb バージョン 1.2

4

5 に答える 5

6

手動で変換することもできます:

ObjectId convertedId = new ObjectId(bigInteger.toString(16));
Query query = new Query(Criteria.where("_id").is(convertedId));
于 2013-07-12T17:06:50.290 に答える
0
//get the converter from the mongoTemplate

MappingMongoConverter converter = (MappingMongoConverter)mongoTemplate.getConverter();

//get the conversion service from the mongo converter

ConversionService conversionService = converter.getConversionService();

//iterate the status list and get the each id to add the arraylist

for(Status status: statusList){

    ObjectId objectIdVal = conversionService.convert(status.getId(), ObjectId.class);

    **//here status.getId() returns the BigInteger**
    statusArrayList.add(objectIdVal);           
}

//get the users list whose status is active  and cancel

query.addCriteria(new Criteria().where("status.$id").in(statusArrayList));

List<User> usersList = mongoTemplate.find(query, User.class);
于 2014-08-21T05:56:00.703 に答える