-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcursores_mongoDB.py
56 lines (44 loc) · 1.19 KB
/
cursores_mongoDB.py
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
# -*- coding: utf-8 -*-
from pymongo import MongoClient
# Conexión con la base de datos llamada "liga" y con la coleccion "premier"
client = MongoClient()
db = client.liga
premierCollection = db.premier
santanderCollection = db.santander
#creación del cursor
cursor = premierCollection.find({"equipo": "Chelsea"})
cursor2 = santanderCollection.find({"equipo":"Real Madrid"})
#
#
# METODOS CRUD SIMPLES
#
#
# Insertar nuevo jugador
def insert_new_player():
santanderCollection.insert({
"jugador" : 'A.Gallego',
"edad" : '25',
"estatura": '1.80',
"equipo" : 'Real Madrid',
"posicion" : 'DEL'
})
print "Insertado correctamente"
client.close()
# Borra los centrocampistas del Chelsea
def remove_med():
for c in cursor:
if c['posicion'] == "MED":
premierCollection.remove(c)
print "Borrado correctamente"
client.close()
# Actualizar la edad
def update_age():
for c in cursor2:
if c['edad'] == "25":
santanderCollection.update(c,{"$set": {"edad": 31}})
print "Actualizado correctamente"
client.close()
if __name__ == '__main__':
insert_new_player()
#remove_med()
#update_age()