File tree Expand file tree Collapse file tree 1 file changed +3
-14
lines changed
Expand file tree Collapse file tree 1 file changed +3
-14
lines changed Original file line number Diff line number Diff line change @@ -80,30 +80,19 @@ class DatabaseSeedingService {
8080 final operations = < Map <String , Object >> [];
8181
8282 for (final item in fixtureData) {
83- final id = getId (item);
84-
85- if (! ObjectId .isValidHexId (id)) {
86- _log.warning ('Skipping document with invalid ID format: $id ' );
87- continue ;
88- }
89-
90- final objectId = ObjectId .fromHexString (id);
83+ // Generate a new ObjectId for each document
84+ final objectId = ObjectId ();
9185 final document = toJson (item)..remove ('id' );
9286
9387 operations.add ({
9488 'replaceOne' : {
95- 'filter' : {'_id' : objectId},
89+ 'filter' : {}, // Match all documents (replace existing or insert new)
9690 'replacement' : document,
9791 'upsert' : true ,
9892 },
9993 });
10094 }
10195
102- if (operations.isEmpty) {
103- _log.info ('No valid documents to write for "$collectionName ".' );
104- return ;
105- }
106-
10796 final result = await collection.bulkWrite (operations);
10897 _log.info (
10998 'Seeding for "$collectionName " complete. '
You can’t perform that action at this time.
0 commit comments