0

Hello and thanks for taking the time to help out. I am trying to find a mongoDB document that has an array.

The array is a list of IDs of users who have read the chat message.

I want to be able to find and/or count the docuemnts that do NOT contain the id of a specified user. That way I can tell who has or has not read the message.

Any pointers in the right direction are appreciated!

I know how to find a document that has an array that contains a value.... but I do not know how to find a document that has an array that does NOT contain a value.

let chatsUnread = await Chat.find({
    chatRoom: rooms[i],
    readMessage: { $all: [!userId] },
  });

Thanks!

3
  • Please add sample data and expected output also will be east if you can create mongoplayground.net Commented Mar 26, 2021 at 23:54
  • You probably need $not $elemMatc, like described at (stackoverflow.com/questions/45567107/…) Commented Mar 27, 2021 at 1:32
  • Please share the schema structure, so that we can construct the query. Commented Mar 27, 2021 at 8:35

0

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.