[JAVA-1092] $all not working Created: 23/Jan/14  Updated: 07/Mar/14  Resolved: 07/Mar/14

Status: Closed
Project: Java Driver
Component/s: Query Operations
Affects Version/s: 2.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Mihaela Hetea Assignee: Trisha Gee
Resolution: Done Votes: 0
Labels: $all, java,
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7, MongoDB Java Driver v2.10.1, MongoDB v2.4.9


Attachments: File students.json    

 Description   

The following code

Test.java

MongoClient client = new MongoClient();
		DB db = client.getDB("school");
		DBCollection collection = db.getCollection("students");
		BasicDBList list = new BasicDBList();
		list.add(new BasicDBObject("$elemMatch",
				new BasicDBObject("type", "homework")));
		BasicDBObject query = new BasicDBObject("scores", new BasicDBObject(
				"$all", list));
		System.out.println(query);
		DBObject cursor = collection.findOne(new BasicDBObject(), query);
		System.out.println(cursor);

returns exception com.mongodb.MongoException: Unsupported projection option: $all
although if you run the command that is printed out in the shell it returns a result without error.

Steps to reproduce:

  • import the attached file in MongoDB
  • run the code


 Comments   
Comment by Jeffrey Yemin [ 07/Mar/14 ]

Apologies for taking so long to get back to you. The problem is that your passing the query as the wrong argument to findOne(). Try this instead:

	DBObject document = collection.findOne(query);

Generated at Thu Feb 08 08:53:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.