0

The scenario is like: I want to append more rows to list in document. The pojo used for holding data to save in mongodb is like this

public class ViewModelOESLog {

private String id;
private List<OESLog> oesLogList;
private List<OESExamLog> oesExamLogList;
int uploadStatus;
   //getter and setter
}

As shown in pojo,document will have structure like id, oesLogList and OesExamLoglist and uploadstatus. During Update,I want to add more rows to oesLogList,consider now oesLogList has rows[0],[1],[2] I want to add more records to this list. I have tried collection.save(),but it replaces the old one. As i am new to Mongodb,please suggest if I can achieve this or not.If yes then how?

callmekatootie
  • 10,989
  • 15
  • 69
  • 104
  • Have you tried an update: http://docs.mongodb.org/manual/reference/method/db.collection.update/ – TeTeT May 29 '14 at 07:28

1 Answers1

0

Retrieve your document data which you want to update(or add more list elements), when you retrieve that, you'll have an object of your class "ViewModelOESLog" containing the data from the retrieved document. Now add more data to the list of this object and then call update on it, new entries will get added to your document. Maybe you could manage it better with this object-database mapper api: https://github.com/impetus-opensource/Kundera/wiki/Blogs--and-Articles

http://recipes4geeks.com/2011/05/02/working-with-mongodb-using-kundera/

Amresh
  • 478
  • 1
  • 6
  • 28
Saheed Hussain
  • 1,096
  • 11
  • 12
  • Thanks....I have already achieved this way.I want to know whether Mongo Db provides provision to update on Record Level or not. – Reena Sharma Jun 02 '14 at 08:41