2013-05-28 5 views
0
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" }) 

Ceci est exécuté dans mongoruncommand est pas un memeber de casbah mongocolection

Comment puis-je utiliser la même dans scala en utilisant casbah Merci

+0

s'il vous plaît formater votre question et d'améliorer libellé –

Répondre

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

@sureshkumar a-t-il fonctionné pour vous? Si oui, veuillez répondre à la question en réponse :) – Ross

Questions connexes