سؤال

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>
هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top