How can I remove the objects from a mongo collection, by passing a list of objects to remove: I am using spring and mongo repository, below is my code:
public void removeDocuments(List<PayloadLogs> listLogs){
String collectionName = mongoTemplate.getCollectionName(Logs.class);
Query removeQuery = Query.query(Criteria.where("typeHash").in(listLogs));
// this does not removes the documents.
this.mongoTemplate.findAllAndRemove(removeQuery, PayloadLogs.class, collectionName);
}
Query log:
db.getCollection('payloadLogs').find({
"creativeHash": {
"$in": [{
"creativeHash": "21540209fa87504bbbb0dd173c41d742",
"lastAccessedAt": null,
....
}]
}
});
"creativeHash"values as a list of those values only. Provided that does identify the documents to remove and it would not match other documents of course.$orinstead. Since$inis essentially "shorthand" for$oron a single property, then that is the logical course. You should spend some time reading Query and Projection Operators and understanding where each is actually applied. Once you understand how each is actually applied, it answers a lot of questions.