-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_database.py
More file actions
44 lines (36 loc) · 1.69 KB
/
Copy pathupdate_database.py
File metadata and controls
44 lines (36 loc) · 1.69 KB
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
# -*- coding: utf-8 -*-
from pymongo import MongoClient
# Connect to default local instance of mongo
client = MongoClient()
# Get database and collection
db = client.kosovoprocurements
collection = db.procurements
def modify_company_slug_and_residence():
if collection.find({'$or': [{"kompania.selia.emri": "", "kompania.selia.slug": ""}, {"kompania.selia.emri": " ", "kompania.selia.slug": ""}]}).count() > 0:
collection.update({
'$or': [{"kompania.selia.emri": "", "kompania.selia.slug": ""},
{"kompania.selia.emri": " ", "kompania.selia.slug": ""}]
},{
"$set": {
"kompania.selia.emri": "n/a",
"kompania.selia.slug": "n/a"}},
multi=True)
print 'Documents with empty values for company name and residence are modified with n/a value.'
else:
print "Company slug and residence : There's no document that needs to be updated."
def delete_documents_with_empty_values():
if collection.find({"kompania.emri": "","kontrata.qmimi":0,"kontrata.vlera":0,"kontrata.qmimiAneks":0,"aktiviteti":"","procedura":"n/a","vlera":"n/a","tipi":"n/a"}).count() > 0:
collection.remove({
"kompania.emri": "",
"kontrata.qmimi": 0,
"kontrata.vlera": 0,
"kontrata.qmimiAneks": 0,
"aktiviteti": "",
"procedura": "n/a",
"vlera": "n/a",
"tipi": "n/a"})
print "Documents with empty values are deleted from the database."
else:
print "Documents with empty values: There's no document that needs to be deleted."
modify_company_slug_and_residence()
delete_documents_with_empty_values()