2

I am trying to extract multiple document types from Mongo database in a single query. If I use find method it requires me to specify class type, and therefore restricting me to get only one document type. For example if I have a collection that contains MongoDocumentA and MongoDocumentB, myList will get MongoDocumentA objects and any other documents will be nulls. Is there anyway around this?

Query query = new Query(Criteria.where("cir_group_status").ne(3).andOperator(Criteria.where("time").gte(startTime),Criteria.where("time").lt (stopTime)));
List myList = mongoOperation.find(query, MongoDocumentA.class);

Much appreciated!

HotPancake
  • 21
  • 1

1 Answers1

0

I don't think this is possible in MongoDB, let alone in Spring's Mongo. If it did exist in Spring, I bet it would just perform two queries.

Take a look at this for some possible workarounds. It is not exactly the same problem as what you are trying to do, but I think the workarounds would be the same.

Community
  • 1
  • 1
Adam
  • 2,214
  • 1
  • 15
  • 26