i have a json data like this,
var data = [ { _id: 5abb46b060808f3a2096f91d,
patient_name: 'krishnaaaannnn',
gender: 'male',
charge_id: 5ab243ac73959deb3ad79fec,
description: 'suffering from pain',
hospital_id: 5aa92df9ec6b3cc78ff88afe,
doctor_id: 5af142f879f06c22f5359be3 },
{ _id: 5af143a779f06c22f5359be4,
patient_name: 'Rajesh',
gender: 'male',
description: 'suffering from fever',
charge_id: 5aaa628e9ae2a2a642b7495c,
hospital_id: 5aa92df9ec6b3cc78ff88afe,
doctor_id: 5af142f879f06c22f5359be3 },
{ _id: 5af144685f2f292b2cc3af6d,
patient_name: 'krishh',
gender: 'male',
description: 'suffering from fever',
charge_id: 5aaa628e9ae2a2a642b7495c,
hospital_id: 5aa92df9ec6b3cc78ff88afe,
doctor_id: 5af142f879f06c22f5359be3 },
{ _id: 5abb46b060808f3a2096f91d,
patient_name: 'krishnaaaannnn',
gender: 'male',
charge_id: 5ab243ac73959deb3ad79fec,
description: 'suffering from pain',
hospital_id: 5aa92df9ec6b3cc78ff88afe,
doctor_id: 5af142f879f06c22f5359be3 } ]
where _id: 5abb46b060808f3a2096f91d
is repeated twice, but i want this data object to be contain unique _id
, please help me to solve
update:
This is my API
to get this data from db, im just getting data from same collection twice, and now i want to make that final json as unique(_id)
function billing_read_all(req, res) {
var auth_data = res.locals.result;
var searchParam = { token: auth_data[0].token }
model.find("doctor", searchParam, function (doctor_data) {
var searchParam1 = { doctor_id: doctor_data[0]._id }
model.find("patient", searchParam1, function (patient_data) {
var searchParam2={charge_id:ObjectId("5ab243ac73959deb3ad79fec")}
model.find("patient", searchParam2, function (patient_data2) {
var data = patient_data.concat(patient_data2)
console.log(_.uniq(data))
res.send(_.uniq(data))
// res.send(patient_data)
})
})
})
}