0

Why does $eq behave differently to $ne in casbah?

import com.mongodb.casbah.Imports._

object O{  
   val x = "user" $ne "bwmcadams"  // Compile fine
   val y = "user" $eq "bwmcadams"  // fails to compile: value = is not a member of string
}

Built with:

    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>casbah-core_2.10</artifactId>
        <version>2.6.0</version>
    </dependency>
user48956
  • 14,850
  • 19
  • 93
  • 154

2 Answers2

2

The $eq operator was added in a later version of Casbah. Try changing your Casbah version to 2.6.3.

cmbaxter
  • 35,283
  • 4
  • 86
  • 95
  • 1
    Hey, you're right. I was looking in the old API docs. However, it doesn't do anything interesting (just wraps a regular DBObject): https://github.com/mongodb/casbah/blob/master/casbah-query/src/main/scala/CoreOperators.scala#L122 – Eve Freeman Jan 02 '14 at 20:31
  • Looks like that was it. Side note: looks like casbah is up to 3.0.0, but only available for scala 2.9.0, sadly... – user48956 Jan 02 '14 at 21:52
  • Casbah 3.0.0 was never officially released and became Casbah 2.3 iirc – Ross Jan 21 '14 at 15:38
0

Instead of $eq, try -> (as a regular tuple). There is no $eq operator in MongoDB: http://docs.mongodb.org/manual/reference/operator/query/ -- equality is the default operator.

Update: It looks like they've removed those conversions from tuples to DBObjects. Try a regular Map:

val y: DBObject = Map("user" -> "bwmcadams")

Update 2: See cmbaxter's answer--they actually did add $eq as an operator ~July 2013, but you don't really need to use it.

Eve Freeman
  • 32,467
  • 4
  • 86
  • 101