0

I want to get unique data for ssn_variations i.e unique b_no and ssn_no without duplication. I am getting data from mongodb

if cr_no in list(json_cr.keys()):
            cr_data = json_cr[cr_no]
            if "ssn_variations" in list(cr_data.keys()):
                ssn_variations = cr_data["ssn_variations"]
                for var_key in ssn_variations.keys():
                    variations = ssn_variations[var_key]
                    b_no = variations["b_no"].strip()
                    ssn_no = variations["ssn_no"].strip()
                    if b_no != "" and ssn_no != "":
                        if b_type == "Borrower":
                            if b_no == "1":
                                self.C1212.append({"borrower_name": encompass_full_name, "ssn_no": ssn_no})
                        else:
                            if b_no == "2":
                                self.C1212.append({"borrower_name": encompass_full_name, "ssn_no": ssn_no})

I am getting a response like this

{
            "ssn_variations" : {
                "1" : {
                    "b_no" : "5",
                    "ssn_no" : "32323"
                },
                "2" : {
                    "b_no" : "2",
                    "ssn_no" : "232323"
                },
                "3" : {
                    "b_no" : "2",
                    "ssn_no" : "232323"
                }
            }
        },

But I want a response like below without duplication.

{
            "ssn_variations" : {
                "1" : {
                    "b_no" : "5",
                    "ssn_no" : "32323"
                },
                "2" : {
                    "b_no" : "2",
                    "ssn_no" : "232323"
                },  
        },

I tried set method but not getting the desired output

MongoDb query to get data

    db.Document_Details_Table.find({"loanNumberId":"4343434","documentId":"434343"})
   .projection({})
   .sort({_id:-1})
   .limit(100)
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153

0 Answers0