Node JS Tutorial for Beginners #35 - Intro to NoSQL / MongoDB

preview_player
Показать описание
Yo gang, in this Node JS tutorial I'll be introducing you to the concept of NoSQL databases and MongoDB, which we're going to use for our to-do application. We'll also be making use of Mongoose, a package which can be installed via the npm, to connect and interact with the database.

----- COURSE LINKS:

---------------------------------------------------------------------------------------------
You can find more front-end development tutorials on CSS, HTML, JavaScript, jQuery, WordPress & more on the channel homepage...

========== JavaScript for Beginners Playlist ==========

============ CSS for Beginners Playlist =============

============== The Net Ninja =====================

================== Social Links ==================

Рекомендации по теме
Комментарии
Автор

i successfully completed this node js awesome series. its supppperr usefull, thankyou sir

althafabbas
Автор


Feel free to contact me if you need assistance.

A big Thank You, Ninja, for teaching us.

liviusosu
Автор

mlab is not working now i think we need to use mongodb atlas

sarcaastech
Автор

Why do you have "__v":0 on every document?

marcosuarez
Автор

can i use the database using mlab if i have no internet?

dongjay
Автор

Help please!!


I've went through the solutions posted here and am still having these issues.



add items to list not working
delete items from list not working

css not rendering on page

todo.ejs file


<html>
<head>
<title>To-Do List</title>



<script language="JavaScript" type="text/javascript"
</head>
<body>
<h1>My To-Do List:</h1>
<div id="todo-table">
<form>
<input type="text" name="item" placeholder="Add new item.." required />
<button type="submit">Add Item</button>
</form>
<ul>
<% for(var i=0; i < todos.length; i++){ %>
<li><%= todos[i].item %></li>
<% } %>
</ul>

</div>
</body>
</html>



todo-list.js file


$(document).ready(function(){ //front end

$('form').on('submit', function(){

var item = $('form input');
var todo = {item: item.val()}; //storing input value set equal to an object 'item' then add it to the item array

$.ajax({
type: 'POST',
url: '/todo',
data: todo,
success: function(data){
//do something with the data via front-end framework
location.reload();
}
});

return false;

});

$('li').on('click', function(){
var item = /g, "-");
$.ajax({
type: 'DELETE',
url: '/todo/' + item,
success: function(data){
//do something with the data via front-end framework
location.reload();
}
});
});

});



todoController.js file


let bodyParser = require('body-parser');

let data = [{item: 'get milk'}, {item: 'walk dog'}, {item: 'kick some coding ass'}];
let urlencodedParser = false});

//file used to manipulate data (to views), handle routes, etc
module.exports = function(app){

//creating handlers for different requests -"request handlers"
app.get('/todo', function(req, res){
res.render('todo', {todos: data});
});

app.post('/todo', urlencodedParser, function(req, res){
data.push(req.body);
res.json(data);
});

app.delete('/todo:item', function(req, res){
data = data.filter(function(todo){
return todo.item.replace(/ /g, '-') !== req.params.item;
});
res.json(data);
});

};

//data manipulation, route handling done here
//.get, .post, .delete are examples of http verbs

Intubationpostmortem
Автор

Nhung Bui Thi < this guy uploads your content

medev
Автор

Hi, does anyone know if I can use Node and mongo in an android project?

juanrios-lmit
Автор

mLab has been closed to new account creation since February 2019.

khaidemsandip
Автор

does mLab still provide free online database?

argasaragih
Автор

u got a great video content but splitting up the video in to 30+ parts will make me go wondering

humanontheinternet
Автор

You can get a beautiful & simple tutorial in Mongoose js Here :

zakariachahboun
Автор

Help please!!


I've went through the solutions posted here and am still having these issues.



add items to list not working
delete items from list not working

css not rendering on page

todo.ejs file


<html>
<head>
<title>To-Do List</title>



<script language="JavaScript" type="text/javascript"
</head>
<body>
<h1>My To-Do List:</h1>
<div id="todo-table">
<form>
<input type="text" name="item" placeholder="Add new item.." required />
<button type="submit">Add Item</button>
</form>
<ul>
<% for(var i=0; i < todos.length; i++){ %>
<li><%= todos[i].item %></li>
<% } %>
</ul>

</div>
</body>
</html>



todo-list.js file


$(document).ready(function(){ //front end

$('form').on('submit', function(){

var item = $('form input');
var todo = {item: item.val()}; //storing input value set equal to an object 'item' then add it to the item array

$.ajax({
type: 'POST',
url: '/todo',
data: todo,
success: function(data){
//do something with the data via front-end framework
location.reload();
}
});

return false;

});

$('li').on('click', function(){
var item = /g, "-");
$.ajax({
type: 'DELETE',
url: '/todo/' + item,
success: function(data){
//do something with the data via front-end framework
location.reload();
}
});
});

});



todoController.js file


let bodyParser = require('body-parser');

let data = [{item: 'get milk'}, {item: 'walk dog'}, {item: 'kick some coding ass'}];
let urlencodedParser = false});

//file used to manipulate data (to views), handle routes, etc
module.exports = function(app){

//creating handlers for different requests -"request handlers"
app.get('/todo', function(req, res){
res.render('todo', {todos: data});
});

app.post('/todo', urlencodedParser, function(req, res){
data.push(req.body);
res.json(data);
});

app.delete('/todo:item', function(req, res){
data = data.filter(function(todo){
return todo.item.replace(/ /g, '-') !== req.params.item;
});
res.json(data);
});

};

//data manipulation, route handling done here
//.get, .post, .delete are examples of http verbs

Intubationpostmortem
Автор

Help please!!


I've went through the solutions posted here and am still having these issues.



add items to list not working
delete items from list not working

css not rendering on page

todo.ejs file


<html>
<head>
<title>To-Do List</title>



<script language="JavaScript" type="text/javascript"
</head>
<body>
<h1>My To-Do List:</h1>
<div id="todo-table">
<form>
<input type="text" name="item" placeholder="Add new item.." required />
<button type="submit">Add Item</button>
</form>
<ul>
<% for(var i=0; i < todos.length; i++){ %>
<li><%= todos[i].item %></li>
<% } %>
</ul>

</div>
</body>
</html>



todo-list.js file


$(document).ready(function(){ //front end

$('form').on('submit', function(){

var item = $('form input');
var todo = {item: item.val()}; //storing input value set equal to an object 'item' then add it to the item array

$.ajax({
type: 'POST',
url: '/todo',
data: todo,
success: function(data){
//do something with the data via front-end framework
location.reload();
}
});

return false;

});

$('li').on('click', function(){
var item = /g, "-");
$.ajax({
type: 'DELETE',
url: '/todo/' + item,
success: function(data){
//do something with the data via front-end framework
location.reload();
}
});
});

});



todoController.js file


let bodyParser = require('body-parser');

let data = [{item: 'get milk'}, {item: 'walk dog'}, {item: 'kick some coding ass'}];
let urlencodedParser = false});

//file used to manipulate data (to views), handle routes, etc
module.exports = function(app){

//creating handlers for different requests -"request handlers"
app.get('/todo', function(req, res){
res.render('todo', {todos: data});
});

app.post('/todo', urlencodedParser, function(req, res){
data.push(req.body);
res.json(data);
});

app.delete('/todo:item', function(req, res){
data = data.filter(function(todo){
return todo.item.replace(/ /g, '-') !== req.params.item;
});
res.json(data);
});

};

//data manipulation, route handling done here
//.get, .post, .delete are examples of http verbs

Intubationpostmortem