de.digitalcollections.iiif.bookshelf.config.mongeez.changeset_002.xml Maven / Gradle / Ivy
<mongoChangeLog> <changeSet changeId="Bookshelf-002" author="ralf"> <script> // Get the collection var collection = db.getCollection('iiif-manifest-summaries'); // Initialize the Ordered Batch var bulk = collection.initializeOrderedBulkOp(); var bulkResult; // Initialize the counter var counter = 0; collection.find({'viewId': {$exists: false}}).forEach(function(doc){ var uri = doc.manifestUri; var prefix = uri.substring(0, uri.indexOf("/manifest")); var viewId = prefix.substring(prefix.lastIndexOf("/") + 1); bulk.find({"_id": doc._id}).updateOne({ '$set': {'viewId': viewId} }); counter++; if(counter % 1000 === 0 ){ bulkResult = bulk.execute(/*function(error, result){ // Re-initialise batch operation bulk = collection.initializeOrderedBulkOp(); }*/); print('Mongeez: migrated ' + counter + ' documents.'); // Re-initialise batch operation bulk = collection.initializeOrderedBulkOp(); } }); if(counter % 1000 !== 0 ){ bulk.execute(); } print('Mongeez: migrated ' + counter + ' documents.'); </script> </changeSet> </mongoChangeLog>