简体   繁体   English

查询多个文档类型Spring Mongo

[英]Query multiple document types Spring Mongo

I am trying to extract multiple document types from Mongo database in a single query. 我试图在单个查询中从Mongo数据库中提取多个文档类型。 If I use find method it requires me to specify class type, and therefore restricting me to get only one document type. 如果我使用find方法,它需要我指定类类型,因此限制我只获得一种文档类型。 For example if I have a collection that contains MongoDocumentA and MongoDocumentB, myList will get MongoDocumentA objects and any other documents will be nulls. 例如,如果我有一个包含MongoDocumentA和MongoDocumentB的集合,myList将获取MongoDocumentA对象,任何其他文档将为空。 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! 非常感激!

I don't think this is possible in MongoDB, let alone in Spring's Mongo. 我不认为这在MongoDB中是可能的,更不用说Spring的Mongo了。 If it did exist in Spring, I bet it would just perform two queries. 如果它确实存在于Spring中,我打赌它只会执行两个查询。

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. 这与你想要做的事情不完全相同,但我认为解决方法是一样的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM