java - Spring Mongo Query, remove objects in collection matching list -
how can remove objects mongo collection, passing list of objects remove: using spring , mongo repository, below code:
public void removedocuments(list<payloadlogs> listlogs){ string collectionname = mongotemplate.getcollectionname(logs.class); query removequery = query.query(criteria.where("typehash").in(listlogs)); // not removes documents. this.mongotemplate.findallandremove(removequery, payloadlogs.class, collectionname); }
query log:
db.getcollection('payloadlogs').find({ "creativehash": { "$in": [{ "creativehash": "21540209fa87504bbbb0dd173c41d742", "lastaccessedat": null, .... }] }
});
i think helpful, add ids list , remove ids
basicdbobject query = new basicdbobject(); list<integer> list = new arraylist<integer>(); list.add(10004); list.add(10005); query.put("_id", new basicdbobject("$in", list)); collection.remove(query);
wiki
Comments
Post a Comment