Users ObjectId migration
This commit is contained in:
parent
4227389a67
commit
fc56bd3273
7 changed files with 72 additions and 91 deletions
31
imports/startup/server/migrations.js
Normal file
31
imports/startup/server/migrations.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* global Migrations */
|
||||
/* eslint-disable import/no-absolute-path */
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
Meteor.startup(() => {
|
||||
// https://github.com/percolatestudio/meteor-migrations
|
||||
|
||||
Migrations.config({
|
||||
// Log job run details to console
|
||||
log: true
|
||||
});
|
||||
|
||||
Migrations.add({
|
||||
version: 1,
|
||||
up: function migrateIds() {
|
||||
// https://docs.mongodb.com/manual/reference/operator/query/type/
|
||||
Meteor.users.find({ _id: { $type: 7 } }).forEach((user) => {
|
||||
const migratedUser = user;
|
||||
const id = user._id.valueOf();
|
||||
console.log(`Migrating id of user: ${JSON.stringify(user)}`);
|
||||
Meteor.users.remove({ _id: user._id });
|
||||
migratedUser._id = id;
|
||||
Meteor.users.insert(migratedUser);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Migrations.migrateTo('latest');
|
||||
|
||||
// Migrations.migrateTo('1,rerun');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue