-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmongo.js
84 lines (70 loc) · 1.47 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
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
const MongoClient = require('mongodb').MongoClient
const url = 'mongodb://localhost:27017'
const dbName = 'mongointro'
MongoClient.connect(url, function (err, client) {
if (err) console.log(err)
console.log('Connected successfully to server')
const db = client.db(dbName)
let usuarios = [
{
username: 'paco',
password: 'asdasdasd',
email: 'mail@mail.com',
datosContacto: {
telefono: '123123123'
},
direccion: {
calle: 'Calle hola',
numero: 123
},
skills: [
'hacker', 'dev'
]
},
{
username: 'luis',
password: 'asdasdasd',
email: 'mail@mail.com',
datosContacto: {
telefono: '123123123'
},
direccion: {
calle: 'Calle hola',
numero: 123
},
skills: [
'design', 'ux', 'dev'
]
},
{
username: 'hugo',
password: 'asdasdasd',
email: 'mail@mail.com',
datosContacto: {
celular: '044 123123123'
},
direccion: {
calle: 'Calle hola',
numero: 123
},
skills: [
'python', 'data-mining'
]
}
]
// Insert Many
db.collection('usuario').insertMany(usuarios, function (err, res) {
if (err) console.log(err)
console.log(res)
})
// Read All
// Read by Skill
//
let posts = [
{
text: 'Hola amigoos',
tags: ['5aa9e404358f902e14369f56','5aa9e404358f902e14369f57']
}
]
client.close()
})