Chapter 4: Admin Backend Ticket: Migration

Inside Migrator project at line 35 it says

You will need to use a ReplaceOneModel

but i did not figure it out how.

datePipelineResults has 23530 records after that I wrote some codes like that

         List<ReplaceOneModel<Movie>> operations = new List<ReplaceOneModel<Movie>>();
            BulkWriteOptions options = new BulkWriteOptions() { IsOrdered = false };

            datePipelineResults.ForEach(c =>
            {
                operations.Add(new ReplaceOneModel<Movie>(new BsonDocument("_id", c.Id), c) { IsUpsert = true });
            });

           
            bulkWriteDatesResult = await _moviesCollection.BulkWriteAsync(operations, options);

but i get error in in the _moviesCollection.BulkWriteAsync line (ss below)

i need some help.

You need to work more on the filters. I would recommend watching the lecture again and then try again. :slight_smile:

Kanika

@kanikasingla The video was all about the way to do this in the Mongo Shell. There was no mention of ReplaceOneModel in the video. This has happened a few times during this course - starting to wonder if there are additional videos that were lost? Can you please check the Ch4 Admin Backend Ticket video and link to the video that explains ReplaceOneModel?

2 Likes

Got your point @Deanna_Delapasse. We will keep this feedback in mind and will add lectures/ documents in future. :slight_smile:

cc @mongocaleb

Kanika

Hi @kanikasingla or anyone else struggling with this. On poking around after realizing the URL in the Migration project was broken I discovered these docs which are more useful than the API docs.https://mongodb.github.io/mongo-csharp-driver/2.10/reference/ I hope that helps someone.

Hello,
@kanikasingla @mongocaleb
I am running Migration Console Application project.
Documents Updated Successfully are
Date Pipeline : 23530
Rating Pipeline : 61

In verify it says : Uh oh. One or both of your pipelines missed 1 documents…

Data pipelines are provided I only add code to write bulk.

When I run MFlix web application and go to Status and click on Migration verification it always fails.

Please help…!!!

What I did was use a LINQ query to convert the datePipelineResults and the ratingPipelineResults to a collection of ReplaceOneModel. The ReplaceOneModel constructor expects the filter to find the document and the new document. So write a filter using Builders and for the second argument simply pass the document.

var models = pipelineResults.Select(movie => new ReplaceOneModel
(
filter,
movie
);

… _collection.BulkWriteAsync(models);

1 Like