【问题标题】:runcommand is not a memeber of casbah mongocolectionrunco​​mmand 不是 casbah mongocolection 的成员
【发布时间】:2013-05-28 04:43:03
【问题描述】:
db.foo.insert( { _id: 1 , desc: "the dog is running" } )
db.foo.insert( { _id: 2 , desc: "the cat is walking" } )
db.foo.ensureIndex( { "desc": "text" } )
db.foo.runCommand( "text", { search : "walk" } )

这是在 mongo 中运行的

如何使用 casbah 在 scala 中运行相同的 谢谢

【问题讨论】:

  • 请正确格式化您的问题并改进措辞

标签: mongodb scala casbah mongodb-scala mongo-scala-driver


【解决方案1】:
import com.mongodb.casbah.Imports._

// Connect to MongoDB
val conn = MongoClient()
val adminDB = conn("admin")

// Turn on textSearchEnabled
adminDB.command(MongoDBObject("setParameter" -> 1, "textSearchEnabled" -> 1))

// Add some sample data to the text db, foo collection
val coll = conn("text")("foo")
coll.dropCollection()
coll.save(MongoDbObject( "_id" -> 1 , "desc" -> "the dog is running"))
coll.save(MongoDbObject( "_id" -> 2 , "desc" -> "the cat is walking"))

// Add a text index
coll.ensureIndex(MongoDBObject("body" -> "desc"))

// Search for walk
coll.db.command(MongoDBObject("text" -> "foo", "search" -> "walk"))

【讨论】:

  • @sureshkumar 这对你有用吗?如果是这样,请将问题标记为已回答:)
猜你喜欢
  • 2011-05-13
  • 1970-01-01
  • 2013-07-03
  • 2018-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多