[英]runcommand is not a memeber of casbah mongocolection
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中以相同方式運行
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"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.