简体   繁体   中英

In MongoDB, is 'users' a default collection?

So I've been learning MEAN through the book 'Mean Machine' and in one of their examples we connect to a db to store user info while creating our RESTful api. Now, every time that we save the user info it gets stored in a collection named 'users' even though no where in the code does it explicitly save to a users collection. Also, when I just create an empty db it does not have the 'users' collection. So, is there something that I'm missing here? Or is 'users' a default collection in MongoDB?

Collection creation in Mongo is implicit . You can simply pretend the collection exists in your code, it will be actually created as necessary. This is keeping in line with the schema-less philosophy: you do not need to declare anything in advance, neither the names of your databases or collections nor the data structure of the documents you're going to store within them.

See https://docs.mongodb.com/manual/core/databases-and-collections/#collections .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM