MongoDB Collections

Learn about MongoDB collections and how to create them in MeteorJS.

What’s a collection?

A collection in MongoDB is a group of MongoDB documents. MongoDB stores data as BSON documents. BSON is a binary representation of JSON.

Documents are composed of field-and-value pairs with the following structure: The { field1: value1, field2: value2, field3: value3, ... fieldN: valueN } structure says that a field’s value can contain any of the BSON data types, which includes other documents, arrays, and arrays of documents.

 const personDoc = {
    _id: ObjectId("5099803df3f4948bd75858581"),
    name: { first: "John", last: "Mansa" },
    dob: new Date('Jun 3, 1967'),
    hobbies: [ "Singing", "Playing Chess", "Skating" ],

    address : {
        lga: "Warri",
        state: "Delta",
        country: "Nigeria"
    }      
}

A database can have multiple collections.

Creating a collection in Meteor

A collection in Meteor is created inside the imports folder. Remember that the imports folder is where we place our application code so that it can be lazily loaded by Meteor.

Get hands-on with 1400+ tech skills courses.