-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquerys - Find (READ)
70 lines (50 loc) · 2.2 KB
/
querys - Find (READ)
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
Crear objetos (Create r u d)
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..])
------------------------------------------------------------------------
Leer/ Buscar campos (c Read u d)
*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.
------------------------------------------------------------------------
Actualizar (c r Update d)
Actualizar campos (C R Update D)
db.collection.updateOne()
db.collection.updateMany()
db.collection.replaceOne()
db.users.updateOne({
age:23,
$set: {age: 30}
})
------------------------------------------------------------------------
Eliminar (c r u Delete)
db.collection.deleteOne()
db.collection.deleteMany()
db.collection.deleteOne({
"_id" : ObjectId(" 12313somehash13123 ")
})
db.collection.deleteMany({
price: {
$lt: 20
}
})
------------------------------------------------------------------------
Agregación
se ejecuta un grupo de queries de otra forma conocidos como "Pipes", que agrupan datos y
con el resultado ejecuta una o mas queries.