0

I have a document in Mongo where by I would like to fetch based on certain criteria.

My LawCase document

{ 
    "_id" : ObjectId("5945f88c9a89205aae0efe9a"), 
    "category" : "DUI", 
    "updated_at" : ISODate("2017-06-18T03:50:36.825+0000"), 
    "created_at" : ISODate("2017-06-18T03:50:36.821+0000"), 
    "lawyer_ids" : [
        "5945f88c9a89205aae0efe99"
    ]
}

My Lawyer Document

{ 
    "_id" : ObjectId("5945f88c9a89205aae0efea8"), 
    "full_name" : "Some Name ", 
    "active" : true, 
    "updated_at" : ISODate("2017-06-18T03:50:36.849+0000"), 
    "created_at" : ISODate("2017-06-18T03:50:36.849+0000"), 
    "law_case_ids" : [
        "5945f88c9a89205aae0efea9", 
        "5945f88c9a89205aae0efeac", 
        "5945f8b59a89205aae0f3f81", 
        "5955d0ff9a89200a57340db8"
    ]
}

Assuming I have the data in place, I need to get 50 documents where category is 'DUI' and lawyer_id is unique.

Any tips?

4
  • Maybe you actually mean "The Top 50 most frequent lawyers per category", which is of course an entirely different question to how you are currently presenting it. Commented Sep 6, 2017 at 1:56
  • Neil. Excellent points and my apologies. Let me explain. I have a many to many relationship between Lawyer & LawCase. A lawyer can have many cases. I just want to be able to get 50 unique lawyers for the category of DUI if they exist. Commented Sep 6, 2017 at 2:01
  • Spend some time writing more detail into your question, then notify in a comment when you have. Touch on such things as 1. Which 50? Any? Ordered in some way? 2. Just for one category at a time? Or multiple? 3. The general purpose of "why" you are doing it, because maybe there are other design approaches. This makes your question clear, and attracts useful answers, that you don't need to ask a stream of questions about yourself. Commented Sep 6, 2017 at 2:05
  • Oh and "of course" if it's a "relationship", then "What bearing does the 'related' data have on results?" which kind of points back to point 1. If you don't ask clearly then you don't get an answer that actually addresses your problem. And likely you get something else entirely, which just results in head scratching trying to figure out how to apply it to what you "really mean". Commented Sep 6, 2017 at 2:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.