-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmongo.js
46 lines (41 loc) · 1.19 KB
/
mongo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const mongoose = require('mongoose');
async function related(artist1, artist2) {
// TODO
console.log(`TODO: provide your implementation to test whether ${artist1} is related with ${artist2}`);
}
async function search(artist1, limit) {
// TODO
console.log(`TODO: provide your implementation to get ${limit} artists related to ${artist1}`);
}
(async () => {
try {
await mongoose.connect('mongodb://bdognom-v2.cs.brown.edu/cdquery1', {
useNewUrlParser: true,
useUnifiedTopology: true,
user: 'cs132',
pass: 'csci1320',
});
} catch (error) {
console.error(error);
}
})();
function close() {
mongoose.disconnect();
}
const argc = process.argv.length;
if (argc == 5) {
switch (process.argv[2]) {
case 'related':
related(process.argv[3], process.argv[4]).then(() => close());
break;
case 'search':
search(process.argv[3], Number.parseInt(process.argv[4])).then(() => close());
break;
default:
console.error(`Invalid command ${process.argv[2]}`);
close();
}
} else {
console.error(`Invalid number of arguments: ${argc} != 5`);
close();
}