Skip to content

Instantly share code, notes, and snippets.

@qrobin
Last active August 27, 2016 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qrobin/4656616088500dbce32341f8b7416683 to your computer and use it in GitHub Desktop.
Save qrobin/4656616088500dbce32341f8b7416683 to your computer and use it in GitHub Desktop.
check(data, Array);
for (let i = 0; i < data.length; i++) {
let item = data[i];
let location_exists = Locations.findOne({
name: item.LOCATION
});
let district_exists = Districts.findOne({
name: item.DISTRICT
});
let place_exists = Places.findOne({
name: item.PLACE_NAME
});
if (!location_exists) {
Locations.insert({
name: item.LOCATION
}, function (l_err, l_res) {
if (l_res) {
if (!district_exists) {
Districts.insert({
name: item.DISTRICT,
location_id: l_res,
}, function (d_err, d_res) {
if (d_res) {
if (!place_exists) {
Places.insert({
name: item.PLACE_NAME,
district_id: d_res,
type: item.PLACE_TYPE,
from_center: item.FROM_AIRPORT
});
} else {
Places.insert({
name: item.PLACE_NAME,
district_id: district_exists._id,
type: item.PLACE_TYPE,
from_center: item.FROM_AIRPORT
})
}
}
})
} else {
Places.insert({
name: item.PLACE_NAME,
district_id: district_exists._id,
type: item.PLACE_TYPE,
from_center: item.FROM_AIRPORT
})
}
}
})
} else {
if (!district_exists) {
Districts.insert({
name: item.DISTRICT,
location_id: location_exists._id,
}, function (d_err, d_res) {
if (d_res) {
if (!place_exists) {
Places.insert({
name: item.PLACE_NAME,
district_id: d_res,
type: item.PLACE_TYPE,
from_center: item.FROM_AIRPORT
});
} else {
Places.insert({
name: item.PLACE_NAME,
district_id: district_exists._id,
type: item.PLACE_TYPE,
from_center: item.FROM_AIRPORT
})
}
}
})
} else {
Places.insert({
name: item.PLACE_NAME,
district_id: district_exists._id,
type: item.PLACE_TYPE,
from_center: item.FROM_AIRPORT
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment