Skip to content

Commit

Permalink
ttl index migration failed probably because the index was created bef…
Browse files Browse the repository at this point in the history
…ore the `time` field
  • Loading branch information
ysavary committed Jul 7, 2024
1 parent d5eeeca commit f3fc0db
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion db-migration/migrate-measurement-collection-to-ttl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ while (cursor.hasNext()) {
const oldCollection = `${station._id}`;
const newCollection = `${station._id}-ttl`;

db[newCollection].createIndex({time: 1}, {expireAfterSeconds: 60 * 60 * 24 * 10});
db[oldCollection].aggregate([
{$set: {receivedAt: {$toDate: {$multiply: ["$time", 1000]}}}},
{$set: {time: {$toDate: {$multiply: ["$_id", 1000]}}}},
{$out: newCollection}]
);
db[newCollection].createIndex({time: 1}, {expireAfterSeconds: 60 * 60 * 24 * 10});
db[newCollection].renameCollection(oldCollection, true);
}
5 changes: 3 additions & 2 deletions winds_mobi_provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ def __create_station(
},
"status": status,
"tz": tz,
"seen": arrow.utcnow().int_timestamp,
"seen": arrow.utcnow().int_timestamp, # deprecated
"lastSeenAt": arrow.utcnow().datetime,
}
return station

Expand Down Expand Up @@ -405,7 +406,7 @@ def create_measure(
measure["rain"] = self.__to_rain(rain)

measure["time"] = arrow.get(measure["_id"]).datetime
measure["receivedAt"] = arrow.now().datetime
measure["receivedAt"] = arrow.utcnow().datetime

fixes = self.mongo_db.stations_fix.find_one(for_station["_id"])
if fixes and "measures" in fixes:
Expand Down

0 comments on commit f3fc0db

Please sign in to comment.