獲得特定領域我在MongoDB的一些文件如下如何從monodb完整的測試搜索結果使用Java
{"Filename":"PHP Book.pdf","Author":"John" ,"Description":"This is my PHP Book"}
{"Filename":"Java Book.html" ,"Author":"Paul" ,"Description":"This is my JAVA Book"}
{"Filename":".NET Book.doc" ,"Author":"James" ,"Description":"This is my .NET Book"}
我建立了描述字段中的文本索引和下面是我的代碼做在說明字段中進行全文搜索。
m = new Mongo("10.0.0.26", 27017);
DB db = m.getDB("soft") ;
DBCollection col = db.getCollection("pocnew") ;
String collection = col.toString();
DBObject searchCmd = new BasicDBObject();
searchCmd.put("text", collection);
searchCmd.put("search", "php");
CommandResult commandResult = db.command(searchCmd);
System.out.println(commandResult);
我得到以下結果
{ "serverUsed" : "/10.0.0.26:27017" , "queryDebugString" : "php||||||" , "language" : "english" , "results" : [ { "score" : 0.5833333333333334 , "obj" : { "_id" : { "$oid" : "51cd7d302d45471420c1132b","Filename":"PHP Book.pdf","Author":"John" ,"Description":"This is my PHP Book"}]}}
我的要求是,只顯示文件名字段的值,即只PHP Book.pdf
請建議我
感謝
System.out.println(commandResult.getString(「Description」)); –
它返回空值 – user2522836