java - Not Able To Insert multiple values into mongodb -


i able insert first values mongodb.how can edit code insert values loop mongodb below code.

public class formatdriver extends configured implements tool{     //my code     public static void main(string[] args) throws exception {          try{             /*connection mongodb*/              while((clusterdata = cluster.readline())!= null){              string[] str_array = clusterdata.split("\\[");              string star_tstr = str_array[0];              string end_str = str_array[1];                string end_array[] = end_str.split(",");              basicdbobject book = new basicdbobject();                  for(int k=0 ; k < doc_array.length ; k++){             /*formating output*/                  if(k%2 == 0){                      if(end_array[0].equals(doc_array[k])){                          end_array[0] = doc_array[k+1];                  book.put("docname",end_array[0]);  //value1                          book.put("clusterno",star_tstr );  //value 2                          books.insert(book);                              /*retrieve*/                           dbcursor cursor = books.find(book);                             while(cursor.hasnext())                                    {                                       system.out.println("in mongo while");                                   system.out.println(cursor.next());                                    }                     }                     }                     }                     }                     }                      } 

can tell me how enter values mongodb.is there wrong in code?

i found answer wrap them in json object ,

basicdbobject out = new basicdbobject();                  out.put("final",jsonobj );                  collection.insert(out); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -