2

I have a posts collection in the following format:

{
    reqID: Int32
    chatID: Int64
    messageID: Int32
    visits: Int32
}

I also have a user collection which has an array field named visits:

visits: [
{
    chatID: Int64
    messageID: Int32
    lastVisit: Int64
}
]

I want to select every post from the first collection where the desired user has not visited it in last 24 hrs. Well this is an outer join, but MongoDB has limited support for outer joins only using $lookup which is appropriate only for simple foreign key lookup. Are there any tricks which can help me to find what I want internally in DMBS?

  • This is also called an anti-join or an anti-semijoin and you are right, it's often done in SQL with an OUTER JOIN and an WHERE .. IS NULL condition. – ypercubeᵀᴹ Dec 18 '16 at 16:34
  • which field do you use to join two collections? – Priyanka Kariya Jan 9 '17 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.