0

I'm using Spring MVC, and have a Conversation entity with the property participants. This is a List of userId Strings who are involved in a particular Conversation. I am trying to retrieve all Conversations whose participants are equal to some List of userIds from a MongoRepository. How do I do this?

I have tried the following:

Conversation findByParticipantsEquals(List<String> participantId);

However the order of participantIds is kind of random so it doesn't necessarily work.

1 Answer 1

1

You can actually use $in operator as shown below:

@Query(value = "{ 'participantId': { $in: ?0 } }")
public List<Conversation> findByParticipantsEquals(List<String> participantIds);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.