
Install MangoDB! Installation command:
C:\DevelopeWithVertin\MEAN\env\mongodb\bin\mongod.exe --dbpath C:\DevelopeWithVertin\MEAN\env\data
Launch MongoDb: C:\DevelopeWithVertin\MEAN\env\mongodb\bin\mongo.exe
In the command prompt of Visual Studio Code type: npm install mongoose
Add this to your models user.js for exemple var mongoose = require('mongoose');
Establish a connection to your mongo database: mongoose.connect('mongodb://localhost/testForAuth', function(err) { if (err) { throw err; } });
Create a table in your user.js remember that you don't need to type sql query with MongoDB var commentaireArticleSchema = new mongoose.Schema({ pseudo : { type : String, match: /^[a-zA-Z0-9-_]+$/ }, contenu : String, date : { type : Date, default : Date.now } });
Insert data in your database: // On le sauvegarde dans MongoDB ! monCommentaire.save(function (err) { if (err) { throw err; } console.log('Commentaire ajouté avec succès !'); // On se déconnecte de MongoDB maintenant mongoose.connection.close(); });
Open a commande prompt and launch the binary file an type the following command to verify that your data has been added properly! use blog switched to db blog show collections commentaires system.indexes db.commentaires.find() { « contenu » : « Salut, super article sur Mongoose ! », « pseudo » : « Atinux », « _id » : ObjectId(« 4e995dab2ea479d40f000001?), « date » : ISODate(« 2011-10-15T10:17:15.829Z ») }
Check out my post on medium.com
You can find a more detailed tutorial at treehouse:
A little boost follow us on YouTube and Facebook!
[You Tube]: https://www.youtube.com/channel/UC2g_-ipVjit6ZlACPWG4JvA?sub_confirmation=1
[Facebook]: https://www.facebook.com/vertingo/




