I’m migrating a Node.js application from Mongoose 5.9.16 to 8.2.3. My primary concern is managing a legacy table,customer_favdrinks__drinks_favoritedcustomers, that contains data related to a many-to-many relationship between Customer and Drinks models.
To establish this relationship in my application, I’m using virtual fields: favDrinks in Customer and favoritedCustomers in Drinks.
I’m unclear about the origin of the customer_favdrinks__drinks_favoritedcustomers table and its interaction with the virtual fields.
I’m seeking advice on:
- A suitable migration strategy to handle the legacy table and ensure data consistency.
- Best practices for using virtual fields in Mongoose 8.2.3 to manage the many-to-many relationship.
Any insights into the behavior of virtual fields in relation to the legacy table would be greatly appreciated.
This is how favDrinks field written in Customer schema, mongoose version 5.9.16
favDrinks:{
collection:'Drinks',
via:'favoritedCustomers'
}
This is how favoritedCustomers field written in Drinks schema, mongoose version 5.9.16
favoritedCustomers:{
collection:'Customer',
via:'favDrinks'
}
I want to push the IDs of favorite drinks whenever a particular drink is selected. These IDs shouldn’t appear in the Drinks or Customer tables. I expect to see these favorited drink IDs when importing a customer’s favorites. This functionality works correctly in the old code. Now, I’m migrating to Mongoose 8.2.3 from 5.9.16, using the same database as the live system.