查询中出现以下$参数错误太多

问题描述:

我正在使用jongo API - org.jongo.MongoCollection是该类。

我有对象ID列表和转换一样ObjectId[],并试图查询作为URL中指定In Jongo, how to find multiple documents from Mongodb by a list of IDs

如何任何建议如下

collection.find("{_id:{$in:#}}", ids).as(Employee.class); 

The query throws the exception - "java.lang.IllegalArgumentException: Too  
many parameters passed to query: {"_id":{"$in":#}}" 

查询不起作用解决?

谢谢。

List尝试它的docs如图所示:

List<String> ages = Lists.newArrayList(22, 63); 
friends.find("{age: {$in:#}}", ages); //→ will produce {age: {$in:[22,63]}} 

例如下面的片段我制作的快速&脏,现在工作对我来说(我用旧的冗长的语法我目前这样的系统...)

List<ObjectId> ids = new ArrayList<ObjectId>(); 
ids.add(new ObjectId("57bc7ec7b8283b457ae4ef01")); 
ids.add(new ObjectId("57bc7ec7b8283b457ae4ef02")); 
ids.add(new ObjectId("57bc7ec7b8283b457ae4ef03")); 
int count = friends.find("{ _id: { $in: # } }", ids).as(Friend.class).count(); 
+0

这不起作用,因为collection.find返回MongoCursor并抛出转换异常。但以下工作正常。如何将MongoCursor隐藏到用户定义的列表中。我使用以下列表 collectionsAsList = new ArrayList (); cursorCollection = collection.find(“{_id:{$ in:#}}”,ids).as(Friends.class); (cursorCollection.hasNext()){ collectionsAsList.add(cursorCollection.next()); } – Kathiresa

+0

它确实有效,但你必须有一个合适的“朋友”课程 - 但这也不是你的问题的主题,但它是如何传递ID列表的方式,这就是问题是否适用于你是否 – DAXaholic

+0

这工作得很好,非常感谢。我有合适的类,但是它正确地转换类型,因为它目前抛出编译错误。是否可以在这里放置一个代码片段? – Kathiresa