Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const MongoClient = require('mongodb').MongoClient
- const url = 'mongodb://localhost:27017/donatemytime';
- MongoClient.connect(url, async function(err, db) {
- console.log("Connected successfully to server");
- const User = db.collection("users")
- const TaskEvent = db.collection("taskevents")
- const Project = db.collection("projects")
- const Application = db.collection("applications")
- const Activity = db.collection("activities")
- const Conversation = db.collection("conversations")
- const Message = db.collection("messages")
- await Application.deleteMany({})
- await Conversation.deleteMany({})
- await Message.deleteMany({})
- await Activity.updateMany({}, {$set: {_appliedVolunteers: []}})
- try {
- const docs = await User.find({ isNgo: true }).toArray()
- for (const doc of docs) {
- const newConversation = {
- context: "pool",
- title: `${doc.ngoName}'s Volunteer Pool`,
- _ngoId: doc._id,
- _participants: [doc._id, ... doc.NGOPoolMembers] // NGO itself + volunteer pool members (more will be added dynamically)
- }
- const savedConversation = await Conversation.insertOne(newConversation)
- const savedDoc = await User.updateOne({ _id: doc._id }, { $set: { _conversationId: savedConversation.insertedId } })
- }
- } catch (err) {
- console.log("ERROR: : ", err)
- }
- try {
- const docs = await Project.find().toArray()
- for (const doc of docs) {
- const newConversation = {
- context: "project",
- title: doc.title,
- _projectId: doc._id,
- _participants: [doc._addedBy] // only the NGO at first; volunteers invloved will be added when applications are approved
- }
- const savedConversation = await Conversation.insertOne(newConversation)
- const savedDoc = await Project.updateOne({ _id: doc._id }, { $set: { _conversationId: savedConversation.insertedId } })
- }
- } catch (err) {
- console.log("ERROR: : ", err)
- }
- try {
- const docs = await TaskEvent.find().toArray()
- for (const doc of docs) {
- const newConversation = {
- context: "taskevent",
- title: doc.title,
- _projectId: doc._projectId,
- _taskEventId: doc._id,
- isTask: doc.isTask,
- _participants: [doc._addedBy] // only the NGO at first; volunteers invloved will be added when applications are approved
- }
- const savedConversation = await Conversation.insertOne(newConversation)
- const savedDoc = await TaskEvent.updateOne({ _id: doc._id }, { $set: { _conversationId: savedConversation.insertedId } })
- }
- } catch (err) {
- console.log("ERROR: : ", err)
- }
- console.log("--------------------- the end ------------------")
- db.close()
- });
Add Comment
Please, Sign In to add comment