@@ -97,7 +97,7 @@ def main_page(request):
97
97
singleproject ['name' ] = project .project_name
98
98
userprojects .append (singleproject )
99
99
for dataset in datasets :
100
- databases += dataset [ ' database' ]
100
+ databases += dataset . database
101
101
return render (request , template_name = "mainpage.html" ,
102
102
context = {'username' : request .user .username , 'projects' : userprojects , 'databases' : databases })
103
103
@@ -1497,6 +1497,18 @@ def sharing_db(dbname, target_user, projectname, username):
1497
1497
mongouri = "mongodb://" + settings .MONGODB_USER + ":" + quote (
1498
1498
settings .MONGODB_PASSWORD ) + "@" + settings .MONGODB_URI + "/admin"
1499
1499
connection = MongoClient (mongouri )
1500
+ existing_dbs = connection .database_names ()
1501
+ checked_all_database_names = 0
1502
+ db_version = 1
1503
+
1504
+ while not checked_all_database_names :
1505
+ checked_all_database_names = 1
1506
+ for dbname in existing_dbs :
1507
+ if str (dbname ) == target_db_name :
1508
+ target_db_name += str (db_version )
1509
+ db_version += 1
1510
+ checked_all_database_names = 0
1511
+ existing_dbs = connection .database_names ()
1500
1512
1501
1513
database = connection [dbname ]
1502
1514
@@ -1519,13 +1531,18 @@ def sharing_db(dbname, target_user, projectname, username):
1519
1531
insertcol = connection [target_db_name ][collection_name ]
1520
1532
skip = 0
1521
1533
collection = col .find (filter = {}, projection = {'_id' : False }, limit = 100 , skip = skip * 100 )
1522
- while collection .count () > 0 :
1534
+
1535
+ items = []
1536
+ for item in collection :
1537
+ items .append (item )
1538
+
1539
+ while len (items ) > 0 :
1523
1540
skip += 1
1541
+ insertcol .insert_many (items )
1542
+ collection = col .find (filter = {}, projection = {'_id' : False }, limit = 100 , skip = skip * 100 )
1524
1543
items = []
1525
1544
for item in collection :
1526
1545
items .append (item )
1527
- insertcol .insert_many (items )
1528
- collection = col .find (filter = {}, projection = {'_id' : False }, limit = 100 , skip = skip * 100 )
1529
1546
1530
1547
connection .admin .command ('grantRolesToUser' , target_user ,
1531
1548
roles = [{'role' : 'dbOwner' , 'db' : target_db_name }])
0 commit comments