java - How to delete mongodb document with two conditions one with $gt operator? -
i retrieve following information:
delete database name = 'aaa' , age>20;
but mongodb in java. essentially, should delete document contain word aaa
, age greater 20 in them. know there $in
operator in mongodb, how do same in java, using java driver? i've been trying everywhere getting nothing. i've tried:
query = new basicdbobject("age", new basicdbobject("$gt", "20"), new basicdbobject("name", "aaa"));
json want delete this.
{"school" : "newschool" , "name" : "aaa" , "age" : "50"}
what want find-term:
{ "name" : "aaa", "age" : { $gt : 20 } }
construct basic db object, or use new 3.x filters create bson you. (as use 3.x, here's appropriate example):
mongoclient client = ... mongodatabase db = client.getdatabase(...); mongocollection<document> coll = db.getcollection(...); coll.deletemany(filters.and(filters.eq("name", "aaa"), filters.gt("age", 20)));
Comments
Post a Comment