List of usage examples for org.springframework.data.mongodb.core.query Query Query
public Query(CriteriaDefinition criteriaDefinition)
From source file:uk.gov.nationalarchives.discovery.taxonomy.common.repository.mongo.impl.IAViewUpdateRepositoryImpl.java
@Override public List<IAViewUpdate> findDocumentsCreatedAfterDocumentAndCreatedBeforeDate(IAViewUpdate afterIAViewUpdate, Date ltDate, Integer limit) { List<Criteria> listOfCriterias = new ArrayList<Criteria>(); listOfCriterias.add(new Criteria().orOperator( Criteria.where(IAViewUpdate.FIELD_CREATIONDATE).gt(afterIAViewUpdate.getCreationDate()), new Criteria().andOperator( Criteria.where(IAViewUpdate.FIELD_CREATIONDATE).gte(afterIAViewUpdate.getCreationDate()), Criteria.where(IAViewUpdate.FIELD_DOCREFERENCE).gt(afterIAViewUpdate.getDocReference())))); if (ltDate != null) { listOfCriterias.add(Criteria.where(IAViewUpdate.FIELD_CREATIONDATE).lt(ltDate)); }//from ww w . ja va 2s .c o m Query query = new Query(new Criteria().andOperator(listOfCriterias.toArray(new Criteria[0]))); query.limit(limit + 1); query.with(new Sort(new Order(Sort.Direction.ASC, IAViewUpdate.FIELD_CREATIONDATE), new Order(Sort.Direction.ASC, IAViewUpdate.FIELD_DOCREFERENCE))); return mongoTemplate.find(query, IAViewUpdate.class); }
From source file:com.pubkit.platform.persistence.impl.DeviceInfoDaoImpl.java
@Override public DeviceInfo getDeviceInfo(String id) { return mongoTemplate.findOne(Query.query(Criteria.where("_id").is(id)), DeviceInfo.class); }
From source file:com.enitalk.controllers.bots.FillWordsRunnable.java
@RabbitListener(queues = "words") public void process(Message msg) { try {//www. j a v a 2 s. c o m ObjectNode word = (ObjectNode) jackson.readTree(msg.getBody()); if (mongo.count(Query.query(Criteria.where("id").is(word.path("id").asInt())), "words") > 0L) { return; } String f = env.getProperty("words.def"); String url = String.format(f, word.path("word").asText()); byte[] def = Request.Get(url).execute().returnContent().asBytes(); JsonNode defJson = jackson.readTree(def); word.set("def", defJson); word.put("i", redis.opsForValue().increment("wc", 1)); mongo.insert(jackson.convertValue(word, HashMap.class), "words"); } catch (Exception e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } }
From source file:org.cbioportal.session_service.domain.internal.SessionRepositoryImpl.java
public Session findOneBySourceAndTypeAndId(String source, String type, String id) { return this.mongoTemplate.findOne( new Query(Criteria.where("source").is(source).and("type").is(type).and("id").is(id)), Session.class, type);//from w ww.ja v a2 s . c om }
From source file:com.comcast.video.dawg.service.park.MongoParkService.java
/** * {@inheritDoc}//from w w w. j ava 2 s . co m */ @Override public DawgModel getModelById(String modelName) { Query query = new Query(Criteria.where("name").is(modelName)); List<DawgModel> models = template.find(query, DawgModel.class, DawgModel.class.getSimpleName()); return models.isEmpty() ? null : models.get(0); }
From source file:example.springdata.mongodb.people.ReactiveMongoTemplateIntegrationTest.java
/** * Note that the all object conversions are performed before the results are printed to the console. *///from w w w.j ava 2s . c o m @Test public void convertReactorTypesToRxJava2() throws Exception { Flux<Person> flux = template.find(Query.query(Criteria.where("lastname").is("White")), Person.class); long count = RxReactiveStreams.toObservable(flux).count().toSingle().toBlocking().value(); assertThat(count).isEqualTo(2); }
From source file:org.openinfinity.tagcloud.domain.repository.TargetRepositoryMongoDBImpl.java
@Override public Collection<Target> loadByTag(Tag tag) { Query query = new Query(Criteria.where("tags").elemMatch(Criteria.where("text").is(tag.getText()))); return mongoTemplate.find(query, Target.class); }
From source file:org.ingini.mongodb.spring.example.read.TestFindOne.java
@Test public void shouldFindOneArrayElement() { //GIVEN//from w w w . j av a2 s. c o m CollectionManager.cleanAndFill(mongoTemplate.getDb(), "characters.json", HumanCharacter.COLLECTION_NAME); //WHEN Hero hero = mongoTemplate.findOne(new BasicQuery( Query.query(Criteria.where("_id").is(new ObjectId("52516b563004ba6b745e864f"))).getQueryObject(), Query.query(Criteria.where("children") .elemMatch(Criteria.where("first_name").is("Sansa").and("last_name").is("Stark"))) .getFieldsObject()), Hero.class); //THEN assertThat(hero).isNotNull(); assertThat(hero.getFirstName()).isEqualTo("Eddard"); }
From source file:org.maodian.flyingcat.im.repository.AccountRepositoryImpl.java
@Override public SimpleUser getSpecificContact(String uid, String targetUid) { String kContId = Account.CONTACTS + "." + SimpleUser.USERNAME; Query query = Query.query(Criteria.where(Account.USERNAME).is(uid).and(kContId).is(targetUid)); query.fields().include(Account.CONTACTS + ".$").exclude("_id"); Account account = getMongoTemplate().findOne(query, Account.class); return account == null ? null : account.getContactList().get(0); }
From source file:quanlyhocvu.api.mongodb.DAO.LopHocDAO.java
public List<LopHocDTO> getLopHocTheoKhoiLop(String idKhoiLop) { Query query = Query.query(Criteria.where("khoiLop.$id").is(new ObjectId(idKhoiLop))); return mongoOperation.find(query, LopHocDTO.class); }