Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Some interesting error  RSS feed

 
Paritosh H Chandorkar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I tried out the following code from the "MongoDB:The Definitive Guide".



I was setting up the criteria for the query.But it gave the error

"com.mongodb.MongoException: Can't canonicalize query: BadValue $all needs an array"

I wonder if it is the driver issue.If so the book needs to be updated.

Would like to have your comments

(Bartender cleanup: added code tags. Please UseCodeTags ←click that link to see how)
 
Junilu Lacar
Sheriff
Posts: 10884
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of the driver are you using? And what version of MongoDB? You should probably check the current driver documentation to see the recommended way to do that. As far as I can tell, that's not the way to do it with the 3.0.0 version of the Java driver. And yes, the value for "$all" should be an array. The driver might take a list though. Give it a try.

I'm taking the course at MongoDB university right now and we are using version 3.0.0. I just completed an exercise where we had to do something similar. If you want to use $all, you have to do something like this:

Or something like that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!