简体   繁体   中英

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" } )

This is run in mongo

How can i run in the same in scala using casbah Thanks

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"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM