Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read me #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// }
// }


const moment = require('moment');
const { MongoClient } = require('mongodb');
require("dotenv").config();
const key = process.env.MONGO_KEY;
Expand Down Expand Up @@ -47,6 +47,8 @@ async function run () {const uri =
console.log('done: ', result);// Close the connection
await client.close();
}


async function run_after() {
const uri =
"mongodb+srv://charity-g:" + key + "@cluster0.n1rc2zq.mongodb.net/?retryWrites=true&w=majority";
Expand All @@ -65,38 +67,49 @@ async function run_after() {
const db = client.db(dbName);

const sourceCollection = db.collection(sourceCollectionName);
const targetCollection = db.collection(targetCollectionName);

// Retrieve the data from the target collection
const targetData = await targetCollection.find().toArray();

const updates = [];
const updates = [];

// Generate the update operations for each source document
await sourceCollection.find().forEach((sourceDoc) => {
const targetField = targetData.find((targetDoc) => targetDoc.profileName === sourceDoc.ig_username)?.fullName;

if (targetField) {
updates.push({
updateOne: {
filter: { _id: sourceDoc._id },
update: { $set: { clubName: targetField } }
}
});
}
});

// Perform the bulk write operation to update multiple documents
const result = await sourceCollection.bulkWrite(updates);
const sourceJsonObjs = await sourceCollection.find().toArray();
console.log(JSON.stringify(sourceJsonObjs))
sourceJsonObjs.map((sourceDoc) => {
// Convert Node.js DateTime object to string format
const dateString = moment(sourceDoc['Date']).utc().format('YYYYMMDD') + 'T';
console.log(dateString); // Output: 20240121

// Convert "HH:MM" string format to string format
const startTimeString = sourceDoc['Start Time'];
const endTimeString = sourceDoc['End Time'];
const fullStartDateTimeString = startTimeString ? dateString + startTimeString.replace(':', '') + '00Z' : null;
const fullEndDateTimeString = endTimeString ? dateString + endTimeString.replace(':', '') + '00Z' : null;
console.log(fullStartDateTimeString + ' ' + fullEndDateTimeString)
if (fullStartDateTimeString && fullEndDateTimeString) {
const ics_desc = "BEGIN:VCALENDAR\nBEGIN:VEVENT\nSUMMARY:" + sourceDoc['Event Title'] + "\nDTSTART:" + fullStartDateTimeString + "\nDTEND: " + fullEndDateTimeString + "\nDESCRIPTION:" + sourceDoc['Event Description'] + "\nLOCATION:" + sourceDoc['Location'] + "\nEND:VEVENT\nEND:VCALENDAR";
updates.push({
updateOne: {
filter: { _id: sourceDoc._id },
update: { $set: { _ics: ics_desc } }
}
});
}
}
);
console.log('---');
console.log(updates.length);
console.log(sourceJsonObjs.length);

// Perform the bulk write operation to update multiple documents
const result = await sourceCollection.bulkWrite(updates);

console.log('Updated count:', result.modifiedCount);
console.log('Updated count:', result.modifiedCount);

console.log('Result:', result);
console.log('Result:', result);

// Close the connection
await client.close();

}


run().catch(console.dir);
run_after().catch(console.dir);
42 changes: 42 additions & 0 deletions backend/getCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { MongoClient } = require("mongodb");
require("dotenv").config();
const key = process.env.MONGO_KEY;


async function getWeeks(weeksFromToday = 0) {
const uri = "mongodb+srv://charity-g:" + key + "@cluster0.n1rc2zq.mongodb.net/?retryWrites=true&w=majority";
const client = new MongoClient(uri)

try {
await client.connect();

const database = client.db('ubc-event-horizon');
const collection = database.collection('events_by_time');
// # Specify the Metafield to be added
// let metafield_name = 'your_metafield_name'
// let metafield_value = 'your_metafield_value'

// // # Update all documents in the collection to add the Metafield
// collection.updateMany(
// {},
// {'$set': {metafield_name: metafield_value}}
// )
// // Execute the query
const eventsData = await collection.find().toArray();
console.log(JSON.stringify(eventsData));
return eventsData; // Return the data
} catch (e) {
throw e; // Throw the error to be handled by the caller
} finally {
await client.close();
}
}

module.exports = getWeeks


async function run() {
getWeeks(1);
};

run().catch(console.dir);
8 changes: 8 additions & 0 deletions backend/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading