Created
May 18, 2021 08:04
-
-
Save cankush625/860f3d4a6e8d80de829e1b93a99d6726 to your computer and use it in GitHub Desktop.
Revisions
-
cankush625 created this gist
May 18, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ import pymongo from bson.code import Code myclient = pymongo.MongoClient("mongodb://localhost:27017/") mydb = myclient["mydb"] mycol = mydb["myColl"] mylist = [ { "resource": "oxygen", "city": "Mumbai", "status": "verified"}, { "resource": "oxygen", "city": "Jaipur", "status": "verified"}, { "resource": "plasma", "city": "delhi", "status": "not verified"}, { "resource": "remdesivir", "city": "Jaipur", "status": "verified"}, { "resource": "plasma", "city": "Banglore", "status": "not verified"}, { "resource": "ICU Bed", "city": "Mumbai", "status": "verified"}, { "resource": "oxygen", "city": "Pune", "status": "not verified"} ] x = mycol.insert_many(mylist) print(x.inserted_ids) for x in mycol.find(): print(x) map1 = Code("function() { emit(this.resource, 1);}") reduce1 = Code("function(key, values) {return Array.sum(values)}") result = mycol.map_reduce(map1, reduce1, "myresult") newcol = mydb["myresult"] for y in newcol.find(): print(y)