I am calling MongoTemplate.find(query, type)
which returns a List<T>
. My question, how do I remove all elements in the list from the DB Collection in one DB call. I know I could create a Query
manually using id
if I know the structure of T
but what if I don't know what T
is.
MongoTemplate
has a remove
method that I can pass T
. What I need is the equivalent removeAll(Collection<T> items, Class<T> type)
EDIT per answer
I need to process each element and determine which ones to remove so I cannot simply pass the Query
to remove
.
Instead of calling find(Query, Class) and then remove all returned documents (a Collection or one-by-one), you can simply call remove(Query, Class) . It's much better that way since you don't have to return all documents to the client, but issue a remove query in the DB itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.