Package org.springframework.data.mongodb.core.query

Examples of org.springframework.data.mongodb.core.query.Query.fields()


    obj.property3 = "P3";

    template.insert(obj);

    Query query = new Query(Criteria.where("id").is(obj.id));
    query.fields() //
        .include("property2") // real property name
        .include("prop3"); // aliased property name

    ObjectWith3AliasedFields result = template.findOne(query, ObjectWith3AliasedFields.class);
View Full Code Here


    obj.property3 = "P3";

    template.insert(obj);

    Query query = new Query(Criteria.where("id").is(obj.id));
    query.fields() //
        .exclude("property2") // real property name
        .exclude("prop3"); // aliased property name

    ObjectWith3AliasedFields result = template.findOne(query, ObjectWith3AliasedFields.class);
View Full Code Here

    template.insert(obj0);
    template.insert(obj1);

    Query query = new Query(Criteria.where("id").in(obj0.id, obj1.id));
    query.fields() //
        .exclude("property2") // real property name
        .exclude("prop3"); // aliased property name

    List<ObjectWith3AliasedFields> results = template.find(query, ObjectWith3AliasedFields.class);
View Full Code Here

    obj.address = address;

    template.insert(obj);

    Query query = new Query(Criteria.where("id").is(obj.id));
    query.fields() //
        .include("property2") // real property name
        .include("address.state"); // aliased property name

    ObjectWith3AliasedFieldsAndNestedAddress result = template.findOne(query,
        ObjectWith3AliasedFieldsAndNestedAddress.class);
View Full Code Here

    doc.dbRefProperty = sample;

    template.save(doc);

    Query qry = query(where("id").is(doc.id));
    qry.fields().include("dbRefProperty");

    List<DocumentWithDBRefCollection> result = template.find(qry, DocumentWithDBRefCollection.class);

    assertThat(result, is(notNullValue()));
    assertThat(result, hasSize(1));
View Full Code Here

   */
  @Test
  public void shouldExcludeDBRefAssociation() {

    Query query = query(where("someString").is("foo"));
    query.fields().exclude("reference");

    BasicMongoPersistentEntity<?> entity = context.getPersistentEntity(WithDBRef.class);
    DBObject queryResult = mapper.getMappedObject(query.getQueryObject(), entity);
    DBObject fieldsResult = mapper.getMappedObject(query.getFieldsObject(), entity);

View Full Code Here

  public void queryMapperShouldBeAbleToProcessQueriesThatIncludeDbRefFields() {

    BasicMongoPersistentEntity<?> persistentEntity = context.getPersistentEntity(WithDBRef.class);

    Query qry = query(where("someString").is("abc"));
    qry.fields().include("reference");

    DBObject mappedFields = mapper.getMappedObject(qry.getFieldsObject(), persistentEntity);
    assertThat(mappedFields, is(notNullValue()));
  }
View Full Code Here

   */
  @Test
  public void getMappedFieldsReplacesTextScoreFieldProperlyCorrectlyWhenPresent() {

    Query query = new Query();
    query.fields().include("textScore");

    DBObject dbo = mapper.getMappedFields(query.getFieldsObject(),
        context.getPersistentEntity(WithTextScoreProperty.class));

    assertThat(dbo, equalTo(new BasicDBObjectBuilder().add("score", new BasicDBObject("$meta", "textScore")).get()));
View Full Code Here

   */
  @Test
  public void shouldExcludeDBRefAssociation() {

    Query query = query(where("someString").is("foo"));
    query.fields().exclude("reference");

    BasicMongoPersistentEntity<?> entity = context.getPersistentEntity(WithDBRef.class);
    DBObject queryResult = mapper.getMappedObject(query.getQueryObject(), entity);
    DBObject fieldsResult = mapper.getMappedObject(query.getFieldsObject(), entity);

View Full Code Here

  public void queryMapperShouldBeAbleToProcessQueriesThatIncludeDbRefFields() {

    BasicMongoPersistentEntity<?> persistentEntity = context.getPersistentEntity(WithDBRef.class);

    Query qry = query(where("someString").is("abc"));
    qry.fields().include("reference");

    DBObject mappedFields = mapper.getMappedObject(qry.getFieldsObject(), persistentEntity);
    assertThat(mappedFields, is(notNullValue()));
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.