Insert field of type Array in MongoDB

In the last video “Understanding JSON” the representation of data storage in the “cast” field of the Array type is written “cast”: [“Leonardo DiCaprio”, “Kate Winslet”, “Kathy Bates”]

But the representation of this field in MongoDB is as follows:
0: “Leonardo DiCaprio”
1: “Kate Winslet”
2: “Kathy Bates”

My question is:
“In an array insert action, do I enter” [“and items separated by commas or indices” 0: Leonardo “,” 1: Kate “,” 2: Kathy "?

Hi @HARRY_76387,

This is just a view in Compass for easier understanding.

No, whenever you are doing any insert in MongoDB you do not need to specify the position of elements in the array.

For instance, this is how I would insert a document having array fields in my database.

db.col.insertOne({“cast”: [“Leonardo DiCaprio”, “Kate Winslet”, “Kathy Bates”]})

I hope this helps. However, if you still have any query please feel free to get back to us.

Happy Learning :slight_smile:

Shubham Ranjan
Curriculum Support Engineer

Hi Shubham_Ranjan,

Thank you very much for your explanations! MongoDB is positively surprising me … I’m changing all my paradigms of the oracle “school” and the other relational databases rsrsrsrs

I am learning a lot!