2013-06-28 60 views
2

如何使用MongoDB的runCommand方法?使用MongoDB的runCommand方法

我使用db.col.runCommand("text",{search:"searchword"})從MongoDB控制檯進行全文搜索。但是我想在Java中使用這個命令,任何人都可以告訴我如何在Java中使用這個命令?

回答

4

你可以試試這個:

DBObject searchCmd = new BasicDBObject(); 
searchCmd.put("text", collection); // the name of the collection (string) 
searchCmd.put("search", query); // the term to search for (string) 
CommandResult commandResult = db.command(searchCmd); 
+0

我得到這個錯誤「無法序列類com.mongodb.DBApiLayer $ MyCollection的」上面的代碼 – user2522836

+0

你可以發佈一些代碼?哪一行?你是否將集合名稱作爲字符串或某種其他對象傳遞? – peshkira

+0

我在這一行收到錯誤CommandResult commandResult = db.command(searchCmd); – user2522836

相關問題