-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo-add-solutions.js
107 lines (90 loc) · 2.41 KB
/
mongo-add-solutions.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict'
const log = console.log
//const MongoClient = require('mongodb').MongoClient;
const {MongoClient, ObjectID} = require('mongodb')
// // Object 'destructuring'
// const student = {name: 'Jimmy', year: 3}
// const {name} = student
// log(name)
const Solutions = require('../models/solution');
/// Connect to the local mongo database
MongoClient.connect('mongodb://test:csc309@ec2-35-183-8-133.ca-central-1.compute.amazonaws.com:27017/', (error, client) => {
if (error) {
return log('error connecting')
} else {
log('Connected to mongo server')
}
const db = client.db('test_db')
// db.collection.createIndex(_id, options)
// // Create a student collection and insert a document into it
// db.collection('solutions').insertOne({
// dept: 'CSC',
// courseNumber: 309,
// year: 2016,
// term: 'Fall',
// type: 'Midterm',
// professor: 'Ken Jackson',
// author: 'jellycsc',
// fileId: 'Solution1.pdf'
// }, (error, result) => {
// if (error) {
// log("can't insert solution")
// } else {
// log(result.ops) // .ops has all the documents added
// log(result.ops[0]._id.getTimestamp())
// }
// })
db.collection('solutions').insertOne({
dept: 'CSC',
courseNumber: 309,
year: 2017,
term: 'Fall',
type: 'Final',
professor: 'Ken Jackson',
author: 'Cosmos',
fileId: 'Solution2.pdf'
}, (error, result) => {
if (error) {
log("can't insert solution")
} else {
log(result.ops) // .ops has all the documents added
log(result.ops[0]._id.getTimestamp())
}
})
// db.collection('solutions').insertOne({
// dept: 'CSC',
// courseNumber: 309,
// year: 2017,
// term: 'Winter',
// type: 'Midterm',
// professor: 'David Liu',
// author: 'Claire',
// fileId: 'Solution3.pdf'
// }, (error, result) => {
// if (error) {
// log("can't insert solution")
// } else {
// log(result.ops) // .ops has all the documents added
// log(result.ops[0]._id.getTimestamp())
// }
// })
// db.collection('solutions').insertOne({
// dept: 'CSC',
// courseNumber: 309,
// year: 2016,
// term: 'Winter',
// type: 'Midterm',
// professor: 'Ken Jackson',
// author: '17Singer',
// fileId: 'Solution4.pdf'
// }, (error, result) => {
// if (error) {
// log("can't insert solution")
// } else {
// log(result.ops) // .ops has all the documents added
// log(result.ops[0]._id.getTimestamp())
// }
// })
// // close the connection
client.close()
})