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

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


   */
  @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


    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 testQueryWithFieldsAndSlice() {
    Query q = new Query(where("name").gte("M").lte("T").and("age").not().gt(22));
    q.fields().exclude("address").include("name").slice("orders", 10);

    String expected = "{ \"name\" : { \"$gte\" : \"M\" , \"$lte\" : \"T\"} , \"age\" : { \"$not\" : { \"$gt\" : 22}}}";
    Assert.assertEquals(expected, q.getQueryObject().toString());
    String expectedFields = "{ \"address\" : 0 , \"name\" : 1 , \"orders\" : { \"$slice\" : 10}}";
    Assert.assertEquals(expectedFields, q.getFieldsObject().toString());
View Full Code Here

   */
  @Test
  public void testQueryWithFieldsElemMatchAndPositionalOperator() {

    Query query = query(where("name").gte("M").lte("T").and("age").not().gt(22));
    query.fields().elemMatch("products", where("name").is("milk")).position("comments", 2);

    String expected = "{ \"name\" : { \"$gte\" : \"M\" , \"$lte\" : \"T\"} , \"age\" : { \"$not\" : { \"$gt\" : 22}}}";
    assertThat(query.getQueryObject().toString(), is(expected));
    String expectedFields = "{ \"products\" : { \"$elemMatch\" : { \"name\" : \"milk\"}} , \"comments.$\" : 2}";
    assertThat(query.getFieldsObject().toString(), is(expectedFields));
View Full Code Here

    container.item = item;

    template.insert(container);

    Query query = new Query(Criteria.where("id").is("foo"));
    query.fields().exclude("item");
    Container result = template.findOne(query, Container.class);

    assertThat(result, is(notNullValue()));
    assertThat(result.item, is(nullValue()));
  }
View Full Code Here

    container.item = item;

    template.insert(container);

    Query query = new Query(Criteria.where("id").is("foo"));
    query.fields().exclude("item");
    Container result = template.findOne(query, Container.class);

    assertThat(result, is(notNullValue()));
    assertThat(result.item, is(nullValue()));
  }
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.