-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-mapreduced.py
55 lines (42 loc) · 1.24 KB
/
2-mapreduced.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
###### Import ########
from bson.code import Code
from pymongo import MongoClient
###### Variable ######
# MongoDB configuration
server = 'localhost'
port = 27017
database = 'pathfinder'
column = 'spells'
###### Function ######
def _conMongoDB(server, port, database, column):
# MongoDB
client = MongoClient(server, port)
db = client[database]
collection = db[column]
return collection
###### Program #######
# Connexion à MongoDB
collection = _conMongoDB(server, port, database, column)
# Map
map = Code(
"function() { "
" if (this.components.length == 1 & this.components == 'V') { "
" emit(this._id, [this.name, this.level, this.components]); "
" } "
"} "
)
# Reduce
reduce = Code(
"function(key, values) {"
" return values; "
"} "
)
# Exécution du MapReduce du la collection
results = collection.map_reduce(map , reduce, "reduced")
# Affichage du résultat obtenu
for result in results.find():
print(result)
# Sortie du programme
exit(0)