-
Notifications
You must be signed in to change notification settings - Fork 3
/
deleteMongoRecords.py
38 lines (28 loc) · 1.14 KB
/
deleteMongoRecords.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Utilitarian script to delete documents in MongoDB
"""
from __future__ import print_function, division
import sys
import pymongo
# { "_id" : "amaltaro_SC_LumiMask_PhEDEx_HG2009_Val_200908_151648_1493" }
def main():
docIds = ["cmsunified_ACDC0_task_EXO-RunIIAutumn18DRPremix-05022__v1_T_200923_122119_7219",
"cmsunified_ACDC0_task_EXO-RunIIFall18wmLHEGS-03451__v1_T_200923_121106_381"]
myClient = pymongo.MongoClient("mongodb://localhost:8230/")
myDB = myClient["msOutDB"]
collections = ["msOutRelValColl", "msOutNonRelValColl"]
# resp = mycol.find(myquery)
for coll in collections:
print("Going to delete documents in the collection: {}".format(coll))
myCol = myDB[coll]
for docName in docIds:
myQuery = {"RequestName": docName}
resp = myCol.find_one_and_delete(myQuery)
if resp:
print(" Deletion result for {}: {}".format(docName, resp["_id"]))
else:
print(" Deletion result for {}: {}".format(docName, resp))
if __name__ == '__main__':
sys.exit(main())