These are chat archives for Automattic/mongoose

17th
Aug 2017
hcmlopes
@hcmlopes
Aug 17 2017 02:56
Hello guys, I have a question and hopefully someone can help.
hcmlopes
@hcmlopes
Aug 17 2017 03:11

I am creating an small app to learn more about node, express and mongo/mongoose. I will be getting some data from a JSON file that looks like this:

{
  "Project": {
    "ProjectName": "2017 Boca Christian Kindergarten Grad",
    "Subjects": [{
      "LastName": "Acevedo",
      "FirstName": "Beatryz",
      "TicketCode": "QCX4WGGH",
      "PackageSummary": "Pkg D",
      "Images": [{
        "FileName": "DAEAZ58S-M02_5963-00024.jpg",
      }],
      "GroupImages": []
    }, {
      "LastName": "Alvarado",
      "FirstName": "Michael",
      "TicketCode": "DHY4SHD2",
      "PackageSummary": "No Packages",
      "Images": [{
        "FileName": "DAEAZ58S-M02_5964-00025.jpg",
      }],
      "GroupImages": []
    }]
  }
}

When I add the data to the database it all gets added at the same time, the project name and all of its subjects. I am not quite sure how I should structure the data in this case. Should I make a collection for the projects and another for the subjects and then link all subjects id inside the Project or should I do one collection in my db that had the whole thing and if so how do I even go about doing that since the number of subjects vary ?

Thanks in advance