2
如何使用MongoDB的runCommand
方法?使用MongoDB的runCommand方法
我使用db.col.runCommand("text",{search:"searchword"})
從MongoDB控制檯進行全文搜索。但是我想在Java中使用這個命令,任何人都可以告訴我如何在Java中使用這個命令?
如何使用MongoDB的runCommand
方法?使用MongoDB的runCommand方法
我使用db.col.runCommand("text",{search:"searchword"})
從MongoDB控制檯進行全文搜索。但是我想在Java中使用這個命令,任何人都可以告訴我如何在Java中使用這個命令?
你可以試試這個:
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);
我得到這個錯誤「無法序列類com.mongodb.DBApiLayer $ MyCollection的」上面的代碼 – user2522836
你可以發佈一些代碼?哪一行?你是否將集合名稱作爲字符串或某種其他對象傳遞? – peshkira
我在這一行收到錯誤CommandResult commandResult = db.command(searchCmd); – user2522836