-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (38 loc) · 1019 Bytes
/
index.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
const { getMongoDb } = require('./mongodbConnection');
// MongoDB & Node.js - CRUD operations for beginners
const run = async () => {
const db = await getMongoDb();
const collection = db.collection('users');
console.log('Starting...');
// CREATE
// await collection.insertOne({
// name: 'Jack',
// age: 21
// });
// await collection.insertMany([
// {
// name: 'Jack',
// age: 21
// },
// {
// name: 'Ami',
// age: 20
// }
// ]);
// READ
// const result = await collection.findOne({ name: 'John' }, { projection: { _id: 0, age: 0 } });
// const resultMany = await collection.find({ age: 20 }, { projection: { _id: 0 } }).toArray();
// UPDATE
// await collection.updateOne({ name: 'Jack' }, {
// $set: {
// age: 25,
// country: 'Belgium'
// }
// });
// DELETE
// await collection.deleteOne({ name: 'Ami' });
// await collection.deleteMany({});
console.log('Process completed.');
process.exit(0);
}
run();