...

/

Coding the Add Author Functionality

Coding the Add Author Functionality

Learn how to add the author's data to the database through MeteorJS methods.

Author schema

The author schema determines the data shape of the author collection. Open the imports/api/authors/authors.js file. This is a file in which the shape of the author object is defined. The shape of an object simply refers to the data types contained in the object.

Press + to interact
const user = {
name: String,
age: Number
}

In the case of the shape of the user object above, the name key should be a string and the age key should be a Number. In the authors.js file, this shape is defined and enforced by the aldeed:collection2 Meteor package upon the insertion and deletion of an author.

Press + to interact
//shape of author data
const author = {
firstname: String,
surname: String,
contactNumber: [String],
contactAddress: String,
emailAddress: String
}

The allow and deny methods of the Mongo collection are set to prevent the insertion of data in the client. Data can only be inserted, updated, or removed through Meteor Methods on the servers that are called by the client.

Author component

Open the imports/ui/AddAuthor.jsx file. There are two major functions of importance that are highlighted in the file. The handleInputChange function is attached to the onChange event of the input textbox on the page. Each input textbox has a value prop that’s equal to its respective state. For example, the first input textbox has a value prop set to name ...