Skip to content

Commit

Permalink
fix migration
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Feb 10, 2021
1 parent 979c665 commit 7d8ed9b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/migrations/001-activePlaylistState.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ async function up({ context: uw }) {

const ops = [];
for await (const keys of uw.redis.scanStream({ match: 'playlist:*' })) {
if (keys.length === 0) {
continue;
}

const values = await uw.redis.mget(keys);
for (const [key, value] of zip(keys, values)) {
for (const [key, playlistID] of zip(keys, values)) {
const userID = key.replace(/^playlist:/, '');

ops.push({
updateOne: {
filter: { _id: new ObjectId(key) },
filter: { _id: new ObjectId(userID) },
update: {
$set: { activePlaylist: new ObjectId(value) },
$set: { activePlaylist: new ObjectId(playlistID) },
},
},
});
Expand Down

0 comments on commit 7d8ed9b

Please sign in to comment.