From 38a9a6d51d014f216690e399f078205f9d340226 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 15 Aug 2012 18:16:03 +0200 Subject: [PATCH] =?UTF-8?q?DATAMONGO-509=20-=20SimpleMongoRepository.exist?= =?UTF-8?q?s(=E2=80=A6)=20now=20avoids=20loading=20unnecessary=20data.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're explicitly ruling out the entities attributes via a field spec to avoid unnecessary object marshaling just to find out whether it exists or not. --- .../mongodb/repository/support/SimpleMongoRepository.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java index 757082bd1..b171e6b66 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java @@ -115,8 +115,11 @@ public class SimpleMongoRepository implements MongoR public boolean exists(ID id) { Assert.notNull(id, "The given id must not be null!"); - return mongoOperations.findOne(new Query(Criteria.where("_id").is(id)), Object.class, - entityInformation.getCollectionName()) != null; + + final Query idQuery = getIdQuery(id); + idQuery.fields(); + + return mongoOperations.findOne(idQuery, entityInformation.getJavaType(), entityInformation.getCollectionName()) != null; } /*