chore: Savepoint before deleting failed mongo integration
This commit is contained in:
parent
4502f41856
commit
9d78a1800f
|
@ -1,6 +1,36 @@
|
||||||
import pkg from 'mongodb';
|
|
||||||
const { MongoClient } = pkg;
|
|
||||||
import { hashString } from "./utils.js"
|
import { hashString } from "./utils.js"
|
||||||
|
import { MongoClient } from 'mongodb'
|
||||||
|
|
||||||
|
const uri = process.env.MONGODB_URI
|
||||||
|
const options = {
|
||||||
|
useUnifiedTopology: true,
|
||||||
|
useNewUrlParser: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
let client
|
||||||
|
let clientPromise
|
||||||
|
|
||||||
|
if (!process.env.MONGODB_URI) {
|
||||||
|
throw new Error('Please add your Mongo URI to .env.local')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
// In development mode, use a global variable so that the value
|
||||||
|
// is preserved across module reloads caused by HMR (Hot Module Replacement).
|
||||||
|
if (!global._mongoClientPromise) {
|
||||||
|
client = new MongoClient(uri, options)
|
||||||
|
global._mongoClientPromise = client.connect()
|
||||||
|
}
|
||||||
|
clientPromise = global._mongoClientPromise
|
||||||
|
} else {
|
||||||
|
// In production mode, it's best to not use a global variable.
|
||||||
|
client = new MongoClient(uri, options)
|
||||||
|
clientPromise = client.connect()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export a module-scoped MongoClient promise. By doing this in a
|
||||||
|
// separate module, the client can be shared across functions.
|
||||||
|
// export default clientPromise
|
||||||
|
|
||||||
function roughSizeOfObject(object) {
|
function roughSizeOfObject(object) {
|
||||||
var objectList = [];
|
var objectList = [];
|
||||||
|
@ -37,7 +67,7 @@ function roughSizeOfObject(object) {
|
||||||
|
|
||||||
export async function upsert(contents, documentName, collectionName = "utitlityFunctionCollection", databaseName = "utilityFunctionExtractorDatabase") {
|
export async function upsert(contents, documentName, collectionName = "utitlityFunctionCollection", databaseName = "utilityFunctionExtractorDatabase") {
|
||||||
const url = process.env.MONGODB_URL
|
const url = process.env.MONGODB_URL
|
||||||
const client = new MongoClient(url);
|
// const client = new MongoClient(url);
|
||||||
try {
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
console.log("Connected correctly to server");
|
console.log("Connected correctly to server");
|
||||||
|
@ -83,10 +113,11 @@ export async function pushToMongo(jsObject) {
|
||||||
export async function mongoRead(documentName, collectionName = "utitlityFunctionCollection", databaseName = "utilityFunctionExtractorDatabase") {
|
export async function mongoRead(documentName, collectionName = "utitlityFunctionCollection", databaseName = "utilityFunctionExtractorDatabase") {
|
||||||
const url = process.env.MONGODB_URL
|
const url = process.env.MONGODB_URL
|
||||||
|
|
||||||
const client = new MongoClient(url, {
|
/*const client = new MongoClient(url, {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
let documentContents
|
let documentContents
|
||||||
try {
|
try {
|
||||||
|
@ -121,10 +152,10 @@ export async function mongoRead(documentName, collectionName = "utitlityFunction
|
||||||
export async function mongoReadWithReadCredentials(documentName, collectionName = "utitlityFunctionCollection", databaseName = "utilityFunctionExtractorDatabase") {
|
export async function mongoReadWithReadCredentials(documentName, collectionName = "utitlityFunctionCollection", databaseName = "utilityFunctionExtractorDatabase") {
|
||||||
const url = "mongodb+srv://metaforecast-frontend:hJr5c9kDhbutBtF1@metaforecastdatabaseclu.wgk8a.mongodb.net/?retryWrites=true&w=majority&useNewUrlParser=true&useUnifiedTopology=true"; // This user only has read permissions, so I'm not excessively worried, and would even be pleased, if someone read this and decided to do something cool with the database.
|
const url = "mongodb+srv://metaforecast-frontend:hJr5c9kDhbutBtF1@metaforecastdatabaseclu.wgk8a.mongodb.net/?retryWrites=true&w=majority&useNewUrlParser=true&useUnifiedTopology=true"; // This user only has read permissions, so I'm not excessively worried, and would even be pleased, if someone read this and decided to do something cool with the database.
|
||||||
|
|
||||||
const client = new MongoClient(url, {
|
/*const client = new MongoClient(url, {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
});
|
});*/
|
||||||
|
|
||||||
let documentContents
|
let documentContents
|
||||||
try {
|
try {
|
||||||
|
@ -158,10 +189,11 @@ export async function mongoReadWithReadCredentials(documentName, collectionName
|
||||||
|
|
||||||
export async function mongoGetAllElements(databaseName = "utilityFunctionExtractorDatabase", collectionName = "utitlityFunctionCollection") {
|
export async function mongoGetAllElements(databaseName = "utilityFunctionExtractorDatabase", collectionName = "utitlityFunctionCollection") {
|
||||||
const url = process.env.MONGODB_URL
|
const url = process.env.MONGODB_URL
|
||||||
const client = new MongoClient(url, {
|
|
||||||
|
/*const client = new MongoClient(url, {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
});
|
});*/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
|
|
1747
package-lock.json
generated
1747
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -9,16 +9,17 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"d3": "^6.7.0",
|
"d3": "^6.7.0",
|
||||||
"dns": "^0.2.2",
|
"dns": "^0.1.2",
|
||||||
"fs": "^0.0.1-security",
|
|
||||||
"mongodb": "^4.1.2",
|
"mongodb": "^4.1.2",
|
||||||
|
"net": "^1.0.2",
|
||||||
"next": "latest",
|
"next": "latest",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"react": "^17.0.1",
|
"react": "^17.0.1",
|
||||||
"react-compound-slider": "^3.3.1",
|
"react-compound-slider": "^3.3.1",
|
||||||
"react-dom": "^17.0.1",
|
"react-dom": "^17.0.1",
|
||||||
"react-markdown": "^6.0.2",
|
"react-markdown": "^6.0.2",
|
||||||
"remark-gfm": "^1.0.0"
|
"remark-gfm": "^1.0.0",
|
||||||
|
"tls": "^0.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^10.0.4",
|
"autoprefixer": "^10.0.4",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user