Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion mongo/create_indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const odeCollections = [
// ODE Json data
{name: "OdeDriverAlertJson", ttlField: "recordGeneratedAt", "timeField": "metadata.odeReceivedAt", intersectionField: null, rsuIP:"metadata.originIp", expireTime: expireSeconds},
{name: "OdeBsmJson", ttlField: "recordGeneratedAt", "timeField": "metadata.odeReceivedAt", intersectionField: null, rsuIP:"metadata.originIp", expireTime: expireSeconds},
{name: "OdeBsmJson", "timeField": "recordGeneratedAt", rsuIP:"metadata.originIp", expireTime: expireSeconds},
{name: "OdeBsmJson", "timeField": "recordGeneratedAt", rsuIP:"metadata.originIp", expireTime: expireSeconds, additionalIndexes: [{"metadata.odeReceivedAt": -1, "payload.data.coreData.position.latitude": 1, "payload.data.coreData.position.longitude": 1}]},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(question) Why not just add another entry for the long lat index like the other indexes do?

{name: "OdeMapJson", ttlField: "recordGeneratedAt", "timeField": "metadata.odeReceivedAt", intersectionField: null, rsuIP:"metadata.originIp", expireTime: expireSeconds},
{name: "OdeMapJson", "timeField": "recordGeneratedAt", rsuIP:"metadata.originIp", expireTime: expireSeconds},
{name: "OdeSpatJson", ttlField: "recordGeneratedAt", "timeField": "metadata.odeReceivedAt", intersectionField: null, rsuIP:"metadata.originIp", expireTime: expireSeconds},
Expand Down Expand Up @@ -232,6 +232,7 @@ do {
createTimeIntersectionIndex(collection);
createTimeRsuIpIndex(collection);
createGeoSpatialIndex(collection);
createAdditionalIndexes(collection);
}else{
missing_collection_count++;
console.log("Collection " + collection['name'] + " does not exist yet");
Expand Down Expand Up @@ -440,6 +441,24 @@ function createGeoSpatialIndex(collection){

}

function createAdditionalIndexes(collection){
for (const additionalIndex of collection['additionalIndexes'] || []) {
console.log("Creating additional index for " + collectionName + " with index: " + JSON.stringify(additionalIndex));
const index_name = Object.entries(additionalIndex).map(([key, value]) => `${key}_${value}`).join("_");
if (indexExists(collection['name'], index_name)) {
continue;
}
try {
db[collectionName].createIndex(additionalIndex);
console.log("Created additional index for " + collectionName + " with index: " + JSON.stringify(additionalIndex));
} catch (err) {
console.log("Failed to create additional index for " + collectionName + " with index: " + JSON.stringify(additionalIndex));
console.log(err);
}
}

}

function ttlIndexExists(collection) {
return db[collection['name']].getIndexes().find((idx) => idx.hasOwnProperty("expireAfterSeconds")) !== undefined;
}
Expand All @@ -459,3 +478,7 @@ function timeIndexExists(collection){
function geoSpatialIndexExists(collection){
return db[collection['name']].getIndexes().find((idx) => idx.name == collection['geoSpatialField'] + "_2dsphere_timeStamp_-1") !== undefined;
}

function indexExists(collectionName, indexName){
return db[collectionName].getIndexes().find((idx) => idx.name == indexName) !== undefined;
}
Loading