Snedden27
Snedden27

Reputation: 1930

Mongo java driver-getting only data not the field name

How to I get my query to return only the data it has and not the field,

For example this is my code

Pattern pattern = Pattern.compile(".*"+textArea.getText()+".*", Pattern.CASE_INSENSITIVE);
BasicDBObject query = new BasicDBObject("content:encoded", pattern);

   model.setRowCount(0);
      BasicDBObject field = new BasicDBObject();
      field.put("title", 1); 
      field.put("_id", 0); 
      DBCursor cursor = blogTable.find(query,field);

      String[] columnNames = {"Title"};               //Jtable headings

     while (cursor.hasNext())
               {
                model.addRow(new Object[]{cursor.next().toString()});
               }

and the output which I get is

{ "title" : "Friday - 9/24/2012"}
{ "title" : "Picture from Pile Gate in Dubrovnik"}
{ "title" : "Saturday - 8/25/2012 - In search of the coffee press"}
{ "title" : "Concert at Church of St. Blaise"}
{ "title" : "DSCN0040"}
{ "title" : "DSCN0041"}
{ "title" : "DSCN0043"}
{ "title" : "DSCN0042"}

I would want it to only have the data part i.e

Friday - 9/24/2012
Picture from Pile Gate in Dubrovnik
Saturday - 8/25/2012 - In search of the coffee press
Concert at Church of St. Blaise
DSCN0040

Thanks in advance.

Upvotes: 1

Views: 117

Answers (1)

Boris Ivanov
Boris Ivanov

Reputation: 4254

Mongodb returning Document in JSON format not particular fields.

Try this code

 while (cursor.hasNext()){
            model.addRow(new Object[]{cursor.next().get("title")});
 }

Upvotes: 1

Related Questions