Announcement Announcement Module
Collapse
No announcement yet.
How to use org.springframework.data.document.mongodb.query.Fi eld Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use org.springframework.data.document.mongodb.query.Fi eld

    With the mongoDB java driver you can specify which fields are relevant for your find result:

    QueryBuilder qb = QueryBuilder.start("keyA");
    qb.in(abcList);
    DBObject query = qb.get();

    BasicDBObject fields = new BasicDBObject();
    fields.append("_id", "1");

    DBCursor cursor = xyzCollection.find(query, fields);
    ...


    How can i use the spring data document Field objects to not query for whole entities but only for certain fields - for example i want as a find result only the ids.

  • #2
    Filters

    Query idQuery = new Query(Criteria.where("email").is(email));
    idQuery.fields().include("_id");
    idQuery.fields().include("societies");
    gosomongo.findOne(idQuery, BasicSocietyScreenData.class, "users");

    Comment


    • #3
      But then the result is a full BasicSocietyScreenData object and not for example a Map of the requested fields only?

      Comment

      Working...
      X