|
@@ -8,21 +8,17 @@ import { type IRevisionModel } from '~/server/models/revision';
|
|
|
export const convertRevisionPageIdToString = async(): Promise<void> => {
|
|
export const convertRevisionPageIdToString = async(): Promise<void> => {
|
|
|
const Revision = mongoose.model<IRevisionHasId, IRevisionModel>('Revision');
|
|
const Revision = mongoose.model<IRevisionHasId, IRevisionModel>('Revision');
|
|
|
|
|
|
|
|
- // Find pageId fields that are not of type string
|
|
|
|
|
- const targetDocuments = await Revision.find({ $expr: { $not: { $eq: [{ $type: '$pageId' }, 'string'] } } });
|
|
|
|
|
-
|
|
|
|
|
- const requests = targetDocuments.map((revision) => {
|
|
|
|
|
- return {
|
|
|
|
|
- updateOne: {
|
|
|
|
|
- filter: { _id: revision._id },
|
|
|
|
|
- update: {
|
|
|
|
|
- $set: {
|
|
|
|
|
- pageId: revision.pageId.toString(),
|
|
|
|
|
|
|
+ // Find and update pageId fields that are not of type string
|
|
|
|
|
+ await Revision.updateMany(
|
|
|
|
|
+ { $expr: { $not: { $eq: [{ $type: '$pageId' }, 'string'] } } },
|
|
|
|
|
+ [
|
|
|
|
|
+ {
|
|
|
|
|
+ $set: {
|
|
|
|
|
+ pageId: {
|
|
|
|
|
+ $toString: '$pageId',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- await Revision.bulkWrite(requests);
|
|
|
|
|
|
|
+ ],
|
|
|
|
|
+ );
|
|
|
};
|
|
};
|