0

Remove in momgodb using java not giving proper result. Am i missing something? My database is as below. enter image description here

My code for removeing records where index = "7" is as,

BasicDBObject whereQuery = new BasicDBObject("nodes.index", new BasicDBObject("$eq", "7"));
node_info.remove(whereQuery);

It's returning all the records and deleting my complete database. What can be probably wrong.?

Hitesh Vaghani
  • 1,342
  • 12
  • 31

1 Answers1

0

Instead of remove try $pull method code as below

BasicDBObject match = new BasicDBObject("_id", object id here);
BasicDBObject update = new BasicDBObject("nodes", new BasicDBObject("index", 7)))
node_info.update(match, new BasicDBObject("$pull", update);
Neo-coder
  • 7,715
  • 4
  • 33
  • 52
  • Superb. Thank you very much. _id is auto-generated so i used match = node_info.findOne() instead of your query. than works well. – Hitesh Vaghani Apr 13 '15 at 09:12
  • #yogesh please have a look at this. http://stackoverflow.com/questions/29625241/finding-document-with-mongodb-using-java – Hitesh Vaghani Apr 14 '15 at 10:39