-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatedb.js
45 lines (33 loc) · 894 Bytes
/
createdb.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
function createUser(err, db){
db.collection('user').insertOne({
name: 'Super Potato',
age: 5,
alias: 'Potato',
address: '1 rue des French Fries'
});
}
function readUser(err, db) {
var cursor = db.collection('user').find();
cursor.each(function (err, doc) {
console.log(doc);
}
}
function updateUser(err,db) {
db.collection('user').updateOne({
{alias: "Mario"}, //Condition
{$set: {address: " "}} //Update
});
}
function deleteUser(err, db){
db.collection('user').deleteOne({alias: 'Potato'});
}
MongoClient.connect(url, create);
var superPotato = {
name: 'Super Potato',
age: 5,
alias: 'Potato',
address: '1 rue des French Fries'
};
MongoClient.connect(url, function(err, db) {
db.collection('user').insertOne(superPotato);
});