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 {
80
80
final operations = < Map <String , Object >> [];
81
81
82
82
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 ();
91
85
final document = toJson (item)..remove ('id' );
92
86
93
87
operations.add ({
94
88
'replaceOne' : {
95
- 'filter' : {'_id' : objectId},
89
+ 'filter' : {}, // Match all documents (replace existing or insert new)
96
90
'replacement' : document,
97
91
'upsert' : true ,
98
92
},
99
93
});
100
94
}
101
95
102
- if (operations.isEmpty) {
103
- _log.info ('No valid documents to write for "$collectionName ".' );
104
- return ;
105
- }
106
-
107
96
final result = await collection.bulkWrite (operations);
108
97
_log.info (
109
98
'Seeding for "$collectionName " complete. '
You can’t perform that action at this time.
0 commit comments