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?

kratos
  • 2,465
  • 2
  • 27
  • 45
  • 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. – Neil Lunn Sep 06 '17 at 01: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. – kratos Sep 06 '17 at 02: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. – Neil Lunn Sep 06 '17 at 02: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". – Neil Lunn Sep 06 '17 at 02:08

0 Answers0