Document querying

I’m facing a challenge. Let’s see documents first

{
  "FullName": "Sarajane Cazares",
  "FromTime": "2023-02-21T19:00:00Z",
  "ToTime": "2023-02-21T20:00:00Z",
  ...
}
...
{
  "FullName": "Marissa",
  "FromTime": "2023-02-21T20:00:00Z",
  "ToTime": "2023-02-21T21:00:00Z",
  ...
}

As you can see, ToTime of doc1 and FromTime of doc2 are same. I need to find all documents where ToTime and FromTime values are same.

Is it possible using MongoDB?

Thanks

When you want to find documents that are related to other documents you simply do a $lookup.

Your use-case is one of the simplest $lookup to do using localField:ToTime and foreignField:FromTime.

Thanks. An aggregate method mixing up with $lookup and $match did my job.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.