You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
812 B
38 lines
812 B
const fs = require("fs");
|
|
const mongoose = require("mongoose");
|
|
const Schema = mongoose.Schema;
|
|
|
|
const dirName = "userScore";
|
|
|
|
const fileNames = fs.readdirSync(dirName);
|
|
|
|
const userScoreSchema = new Schema({
|
|
authorID: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
score: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
});
|
|
|
|
const userScore = mongoose.model("UserScore", userScoreSchema);
|
|
|
|
mongoose
|
|
.connect(process.env.MONGO_URI, {
|
|
useUnifiedTopology: true,
|
|
useNewUrlParser: true,
|
|
})
|
|
.then(() => {
|
|
fileNames.forEach(file => {
|
|
fs.readFile(dirName + "/" + file, 'utf-8', (err, content) => {
|
|
const migrateScore = new userScore({
|
|
authorID: file,
|
|
score: content,
|
|
});
|
|
migrateScore.save();
|
|
});
|
|
});
|
|
})
|
|
.catch((err) => console.log(err));
|
|
|