Abheek Dhawan
4 years ago
5 changed files with 47 additions and 8 deletions
@ -0,0 +1,38 @@ |
|||||
|
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)); |
@ -1 +0,0 @@ |
|||||
8 |
|
Loading…
Reference in new issue