-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongodb.js
155 lines (134 loc) · 3.63 KB
/
mongodb.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*Course notes ------------------------------------------------------
There is no god damn difference between double quotes ( " ") and single quotes ( '' ).
*insert one
db.users.insertOne( {...code... })
*insert many es un array
db.users.insertMany( [..code..])
*db.users.find()
returns this: 5d73f3cde188590010d4ee1c
gets you the hash that will replace the id we used to create our schema
*db.users.find( object: somethign )
- db.users.find( username: "hugo" ) (busca el usuario con username Hugo pero falla por que se le mando "hugo" como si fuera la comparacion == ,
Tambien se pueden hacer regex en los querys
- db.users.find( username: /hugo/i ) (ignora las mayusculas y minusculas, haciendo posible la busqueda del texto)
*db.users.find( {age: {$gt: 25} } ) el uso de $ representa el uso de funciones internas de mongoDB, en este caso "$gt" busca el valor mayor (greter than..)
por ende "$lt" busca el valor menor que...
mas info aqui https://bit.ly/2kAdtTo
*db.users.find({age: {$gt: 25} }).sort({age: +1})
*db.users.find( {$and: [ {author:null}, {created_by: {$exists:true } }] })
db.users.find({
$and:[ {author:null}, {created_by: {$exists:true } }] })
*db.users.find().pretty()
gets you a better view of the object with indentation and shit.
Course notes ------------------------------------------------------ */
//Users Collection
{
_id: ObjectId('1'),
username: "Hugo",
age: 23,
password: "cursodemongodb1",
rol:['admin', 'client'],
email: "[email protected]",
facebook: "HugoGtz",
active: true,
author: ObjectId('5d73f3cde188590010d4ee1c')
},
{
_id: ObjectId('2'),
username: "Admin Codificadas",
password: "datosmongo",
rol: ['admin'],
active: true,
created_by: ObjectId('d73f3cde188590010d4ee1c'),
author: null
} //)
//------------------------------------------------------------------
//Blog collection
{
name: "Codificadas",
url: "codificadas.blog.mx",
author: ObjectId('2')
}
//Blog entry
{
article: "Something good",
publishDate: '2019-09-07',
blog: ObjectId('1'),
comments: [
{
comment: 'dude!',
createBy: ObjectId('1'),
}
],
tag: ['tag1', 'tag2' , 'tag3']
}
//------------------------------------------------------------------
//Servers 1
//Best way
{
servername: "Hal_9000",
type: 'access',
entrys: [
{
date: timestamp,
code: 404,
msg: "Not found",
}
]
}
//Servers 2
//Ok way
{
id: Object('1'),
servername: "Hal_9000",
type: 'access'
}
{
date: timestamp,
code: 404,
msg: "Not found",
ObjectId: ('1')
}
//------------------------------------------------------------------
//Conversation collection
{
name: "codificadasgroup"
messages:[
{
text:"Hola mundo",
created_by: ('1'),
},
{
text:"howdy",
created_by: ('2'),
}
]
}
//------------------------------------------------------------------
//Employee collection
{
_id: ObjectId('10'),
name: "Steven",
BDate: '2019-09-07',
Adress: "1kdnaosdnoansd",
salary: 110.10,
Sex: "m",
WorksFor: ObjectId(3),
Manages: ObjectId(4),
Supervisesr: ObjectId(5)
department: ObjectId('1')
}
//Department collection
{
_id: ObjectId('1'),
name: 'Tecnologia'
number: 1,
location: 'planta baja',
projects: [
{
name: "code",
number: 5,
location: "somewhere",
}
]
}