Search code examples
springmongodbspring-bootcriteria

Change mongodb Criteria content in spring


So I have a Criteria for mongodb constructed and I want to check the content of it, and change it if needed. I couldn't find anyway how to do that. To be more precise, I wanna know which fields are included and which values are there and change them based on some logic.


Solution

  • So Answering my own question: In order to achieve the above you need a piece of code like this

    final Document document = (Document) filterCriteria.getCriteriaObject().get(whatever request param you need)
    
    Collection<ObjectId> ids = (Collection<ObjectId>) document.values().stream().getwhateverIdsOrParams you need.
    

    I hope this helps somebody.