Help With Interrelated Data Files for MongoDB?

github logo ・1 min read

Hi all 👋

I have been wrestling with this issue for ages and getting slightly closer, but the progress is painfully slow. Hopefully someone can help me... 🙏

How can I write interrelated data populate a mongodb database?

Here's an example, I have a series of JavaScript files:

Weapon File - (to go to weapon collection)

[
    {
    name: "Sword",
    damage: 8,
    damageType: ObjectID
    }
]

Damage Type File (to go to damage type collection)

[
    {
    name: "Slicing",
    weapons: [ObjectID, ObjectID]
    }
]

Where ObjectID would refer to the _id of the interrelated data. In this case a weapon would have a damageType and a Damage Type would have a series of weapons.

How would I write those javascript files since the _id field is generated by mongodb?

Any help would be greatly appreciated 😄

Cheers
Pete

twitter logo DISCUSS
Classic DEV Post from Apr 1

How I Write Online Articles

How you can write online articles

porgeet profile image
Graphic/digital designer diving into the world of development to be able to make cool sh*t.