|
MongoDB collections are essentially named groupings of documents. You can think of them as roughly equivalent to relational database tables. DetailsA MongoDB collection is a collection of BSON documents. These documents are usually have the same structure, but this is not a requirement since MongoDB is a schema-free database. You may store a heterogeneous set of documents within a collection, as you do not need predefine the collection's "columns" or fields. A collection is created when the first document is inserted. Collection names should begin with letters or an underscore and may include numbers; $ is reserved. Collections can be organized in namespaces; these are named groups of collections defined using a dot notation. For example, you could define collections blog.posts and blog.authors, both reside under "blog". Note that this is simply an organizational mechanism for the user -- the collection namespace is flat from the database's perspective. Programmatically, we access these collections using the dot notation. For example, using the mongo shell: if( db.blog.posts.findOne() ) print("blog.posts exists and is not empty."); See also: |

Add Comment