-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(contribute_productions): update schemas
- Loading branch information
Showing
10 changed files
with
92 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
client/src/pages/api-operation-page/link-publications/contributor-production-info.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { MongoClient } from "mongodb"; | ||
|
||
const mongoURI = process.env.MONGO_URI || "mongodb://localhost:27017"; | ||
const client = new MongoClient(mongoURI); | ||
|
||
// THIS SCRIPT IS USED TO RENAME "id" FIELD TO "objectId" | ||
// USE IT DIRECTLY IN PROD | ||
|
||
console.log(mongoURI); | ||
async function renameIdToObjectId() { | ||
try { | ||
await client.connect(); | ||
console.log("Connecté à MongoDB"); | ||
|
||
const db = client.db("ticket-office-api"); | ||
// change collection if needed | ||
const collection = db.collection("contribute_productions"); | ||
|
||
const contacts = await collection.find().toArray(); | ||
console.log(`Nombre de contacts trouvés : ${contacts.length}`); | ||
|
||
for (const contact of contacts) { | ||
// Vérifie si le champ 'id' existe avant de le renommer | ||
if (contact.id) { | ||
try { | ||
// Renomme le champ 'id' en 'objectId' | ||
await collection.updateOne( | ||
{ _id: contact._id }, | ||
{ | ||
$rename: { id: "objectId" }, | ||
} | ||
); | ||
|
||
console.log(`Document mis à jour pour l'ID : ${contact._id}`); | ||
} catch (error) { | ||
console.error( | ||
`Impossible de renommer le champ id en objectId pour le document : ${contact._id}`, | ||
error | ||
); | ||
} | ||
} | ||
} | ||
|
||
console.log("Renommage terminé avec succès."); | ||
} catch (error) { | ||
console.error("Erreur lors du renommage :", error); | ||
} finally { | ||
await client.close(); | ||
} | ||
} | ||
|
||
renameIdToObjectId(); |