Skip to content
Advertisement

MongoDB Problems while inserting nested data

I try to build a database for a giveaway bot using MongoDB. Once a new giveaway is created the bot runs the following code to write the new giveaway into the databank:

JavaScript

Giveaways should be a nested document in the document with the server’s information. My schemas for this looks like this:

JavaScript

In my Mongo Atlas I have 2 collections mainSchema und giveawaySchema. If I run this code I only get an entry under ‘giveawaySchema’ consisting of this:

JavaScript

I don’t get any data in the mainSchema collection. Does anyone know what is the error? Thank you for your help in advance.

Advertisement

Answer

You should change your models exports to:

JavaScript

Then, try to create the Giveaway entity before the Main one, and add that one to the new Main document:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement