我在这份文件中收集了一份“A”:
{
"InsuranceCompany" : {
"fieldlabel" : "InsuranceCompany",
"fieldname" : "InsuranceCompany",
"fieldtype" : "dropdown",
"required" : "1",
"default_value" : "",
"placeholder" : "InsuranceCompany",
"order_no" : "3",
"formgroup" : "policyDetails",
"can_delete" : "1",
"status" : "1"
},
"PolicyNumber" : {
"fieldlabel" : "PolicyNumber",
"fieldname" : "PolicyNumber",
"fieldtype" : "text",
"required" : "1",
"default_value" : "",
"placeholder" : "Policy Number",
"order_no" : "1",
"formgroup" : "policyDetails",
"can_delete" : "1",
"status" : "1"
},
"NoOfYear" : {
"fieldlabel" : "NoOfYear",
"fieldname" : "NoOfYear",
"fieldtype" : "text",
"required" : "1",
"default_value" : "",
"placeholder" : "No Of Year",
"order_no" : "2",
"formgroup" : "policyDetails",
"can_delete" : "1",
"status" : "1"
}
}
我想根据order_no对它进行排序,结果应该是:
{
"PolicyNumber" : {
"fieldlabel" : "PolicyNumber",
"fieldname" : "PolicyNumber",
"fieldtype" : "text",
"required" : "1",
"default_value" : "",
"placeholder" : "Policy Number",
"order_no" : "1",
"formgroup" : "policyDetails",
"can_delete" : "1",
"status" : "1"
},
"NoOfYear" : {
"fieldlabel" : "NoOfYear",
"fieldname" : "NoOfYear",
"fieldtype" : "text",
"required" : "1",
"default_value" : "",
"placeholder" : "No Of Year",
"order_no" : "2",
"formgroup" : "policyDetails",
"can_delete" : "1",
"status" : "1"
},
"InsuranceCompany" : {
"fieldlabel" : "InsuranceCompany",
"fieldname" : "InsuranceCompany",
"fieldtype" : "dropdown",
"required" : "1",
"default_value" : "",
"placeholder" : "InsuranceCompany",
"order_no" : "3",
"formgroup" : "policyDetails",
"can_delete" : "1",
"status" : "1"
}
}
我试过这个问题:
db.A.aggregate([
{ $sort : { order_no : -1 } }
]).pretty()
但它对我不起作用,因为它返回相同的序列。