mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
chore(tools): update mongodb in seed script (#50519)
This commit is contained in:
committed by
GitHub
parent
4a9c0a4886
commit
41372c31cd
@@ -1,8 +1,8 @@
|
||||
/* eslint-disable max-len */
|
||||
const ObjectId = require('mongodb').ObjectID;
|
||||
const { ObjectId } = require('mongodb');
|
||||
|
||||
module.exports = {
|
||||
_id: ObjectId('5fa2db00a25c1c1fa49ce067'),
|
||||
_id: new ObjectId('5fa2db00a25c1c1fa49ce067'),
|
||||
email: 'foo@bar.com',
|
||||
emailVerified: true,
|
||||
progressTimestamps: [],
|
||||
|
||||
@@ -22,6 +22,6 @@
|
||||
"debug": "4.3.4",
|
||||
"dotenv": "16.0.3",
|
||||
"lodash": "4.17.21",
|
||||
"mongodb": "3.7.3"
|
||||
"mongodb": "5.5.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ function handleError(err, client) {
|
||||
}
|
||||
|
||||
const demoUser = {
|
||||
_id: ObjectId('5bd30e0f1caf6ac3ddddddb5'),
|
||||
_id: new ObjectId('5bd30e0f1caf6ac3ddddddb5'),
|
||||
email: 'foo@bar.com',
|
||||
emailVerified: true,
|
||||
progressTimestamps: [],
|
||||
@@ -91,7 +91,7 @@ const demoUser = {
|
||||
};
|
||||
|
||||
const blankUser = {
|
||||
_id: ObjectId('5bd30e0f1caf6ac3ddddddb9'),
|
||||
_id: new ObjectId('5bd30e0f1caf6ac3ddddddb9'),
|
||||
email: 'bar@bar.com',
|
||||
emailVerified: true,
|
||||
progressTimestamps: [],
|
||||
@@ -151,77 +151,48 @@ const blankUser = {
|
||||
unsubscribeId: 'ecJxUi7OM49f24hTpauP8'
|
||||
};
|
||||
|
||||
MongoClient.connect(MONGOHQ_URL, { useNewUrlParser: true }, (err, client) => {
|
||||
handleError(err, client);
|
||||
const client = new MongoClient(MONGOHQ_URL, { useNewUrlParser: true });
|
||||
|
||||
log('Connected successfully to mongo');
|
||||
log('Connected successfully to mongo');
|
||||
|
||||
const db = client.db('freecodecamp');
|
||||
const user = db.collection('user');
|
||||
const db = client.db('freecodecamp');
|
||||
const user = db.collection('user');
|
||||
|
||||
const dropUserTokens = async function () {
|
||||
await db.collection('UserToken').deleteMany({
|
||||
userId: {
|
||||
$in: [
|
||||
ObjectId('5fa2db00a25c1c1fa49ce067'),
|
||||
ObjectId('5bd30e0f1caf6ac3ddddddb5'),
|
||||
ObjectId('5bd30e0f1caf6ac3ddddddb9')
|
||||
]
|
||||
}
|
||||
});
|
||||
};
|
||||
const userIds = [
|
||||
new ObjectId('5fa2db00a25c1c1fa49ce067'),
|
||||
new ObjectId('5bd30e0f1caf6ac3ddddddb5'),
|
||||
new ObjectId('5bd30e0f1caf6ac3ddddddb9')
|
||||
];
|
||||
|
||||
const dropUserTokens = async function () {
|
||||
await db.collection('UserToken').deleteMany({
|
||||
userId: {
|
||||
$in: userIds
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const dropUsers = async function () {
|
||||
await db.collection('user').deleteMany({
|
||||
_id: {
|
||||
$in: userIds
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const run = async () => {
|
||||
await dropUserTokens();
|
||||
await dropUsers();
|
||||
if (process.argv[2] === 'certified-user') {
|
||||
dropUserTokens();
|
||||
user.deleteMany(
|
||||
{
|
||||
_id: {
|
||||
$in: [
|
||||
ObjectId('5fa2db00a25c1c1fa49ce067'),
|
||||
ObjectId('5bd30e0f1caf6ac3ddddddb5'),
|
||||
ObjectId('5bd30e0f1caf6ac3ddddddb9')
|
||||
]
|
||||
}
|
||||
},
|
||||
err => {
|
||||
handleError(err, client);
|
||||
|
||||
try {
|
||||
user.insertOne(fullyCertifiedUser);
|
||||
user.insertOne(blankUser);
|
||||
} catch (e) {
|
||||
handleError(e, client);
|
||||
} finally {
|
||||
log('local auth user seed complete');
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
);
|
||||
await user.insertOne(fullyCertifiedUser);
|
||||
await user.insertOne(blankUser);
|
||||
} else {
|
||||
dropUserTokens();
|
||||
user.deleteMany(
|
||||
{
|
||||
_id: {
|
||||
$in: [
|
||||
ObjectId('5fa2db00a25c1c1fa49ce067'),
|
||||
ObjectId('5bd30e0f1caf6ac3ddddddb5'),
|
||||
ObjectId('5bd30e0f1caf6ac3ddddddb9')
|
||||
]
|
||||
}
|
||||
},
|
||||
err => {
|
||||
handleError(err, client);
|
||||
|
||||
try {
|
||||
user.insertOne(demoUser);
|
||||
user.insertOne(blankUser);
|
||||
} catch (e) {
|
||||
handleError(e, client);
|
||||
} finally {
|
||||
log('local auth user seed complete');
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
);
|
||||
await user.insertOne(demoUser);
|
||||
await user.insertOne(blankUser);
|
||||
}
|
||||
});
|
||||
log('local auth user seed complete');
|
||||
};
|
||||
|
||||
run()
|
||||
.then(() => client.close())
|
||||
.catch(err => handleError(err, client));
|
||||
|
||||
Reference in New Issue
Block a user