Beispiel #1
0
        public void RunAll()
        {
            var locations = _collectionLocator.GetLocatesOrEmpty();

            foreach (var locate in locations)
            {
                var information       = locate.Value;
                var type              = locate.Key;
                var databaseName      = GetDatabaseOrDefault(information);
                var collectionVersion = _versionService.GetCollectionVersion(type);

                var collection = _client.GetDatabase(databaseName)
                                 .GetCollection <BsonDocument>(information.Collection);

                var bulk = new List <WriteModel <BsonDocument> >();

                var query = CreateQueryForRelevantDocuments(type);

                using (var cursor = collection.FindSync(query))
                {
                    while (cursor.MoveNext())
                    {
                        var batch = cursor.Current;
                        foreach (var document in batch)
                        {
                            _migrationRunner.Run(type, document, collectionVersion);


                            var update = new ReplaceOneModel <BsonDocument>(
                                new BsonDocument {
                                { "_id", document["_id"] }
                            },
                                document
                                );

                            bulk.Add(update);
                        }
                    }
                }

                if (bulk.Count > 0)
                {
                    collection.BulkWrite(bulk);
                }
            }
        }