How to create new Document that is an array

Hi! First post and relatively new to mongo db. Also I have hit my google limit and might switch back to sql database if I can’t figure this out soon :slight_smile:

Question: How do I create a document of the schema below? Specifically how do I create the profile with only the array data field, disccollection, filled out. I have this schema implemented in the demo, however I have to create the profile first. Then after the profile is created, then I was able to add data to the disccollection field.

To restate the question: How do I create a document in mongo db atlas that is only an array of objects.

I am using nodejs and mongoose to connect with mongo atlas.

Background info: The demo and github for the app I am working is listed below

const ProfileSchema = new mongoose.Schema({
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "user",
  },
  favoritedisc: {
    type: String,
  },
  disccollection: [
    {
      discname: {
        type: String,
        required: true,
      },
      discmanufacturer: {
        type: String,
      },    },  ],});

Working demo (it is using a free dyno on mongo atlas so give it a second to load if the dyno is asleep ). If you register an account, you will have to create a profile, before being able to create your disc golf bag. If you click on Create Disc Bag it just goes to empty page. That is not related to my mongo db issue.
https://enigmatic-beyond-47734.herokuapp.com/

Thanks, Dan

Hi @Daniel_Westlund,

Not sure what you mean by a document who “is just an array of documents”

But in MongoDB the basic storing structure is JSON document with the _id unique field. So you can still create documents like:

{
_id : ...,
disccollection : [ { ... } , ...]
}

Perhaps I don’t understand your intention but when query you can project only the array field and your clients will get just this fields array…

Please note that we have programs like github students pack where you can get credit and continue with Atlas .

Plus atlas have free tier clusters so you don’t have to pay for those.

Let me know what am I missing.

Best
Pavel