我想获得ssn_variations的唯一数据,即唯一b_no
且ssn_no
没有重复。我正在从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})
我收到这样的回复
{
"ssn_variations" : {
"1" : {
"b_no" : "5",
"ssn_no" : "32323"
},
"2" : {
"b_no" : "2",
"ssn_no" : "232323"
},
"3" : {
"b_no" : "2",
"ssn_no" : "232323"
}
}
},
但我想要一个像下面这样没有重复的回应。
{
"ssn_variations" : {
"1" : {
"b_no" : "5",
"ssn_no" : "32323"
},
"2" : {
"b_no" : "2",
"ssn_no" : "232323"
},
},
我尝试set
了方法但没有得到所需的输出
MongoDb 查询获取数据
db.Document_Details_Table.find({"loanNumberId":"4343434","documentId":"434343"})
.projection({})
.sort({_id:-1})
.limit(100)