---restore content starts---
Development using Webstorm 9
New nodejs+express project Newfarmer
Article Directory
- Configure Mongoose
- Creating Directories and files
- Insert data, Post commit JSON add a record
- Query data, remove newly added records
1. Configure Mongoose
Increase the class library of Mongoose
NPM Install Mongoose--save
2. Creating Directories and files
In the models directory, increase the Mongodb.js file database connection file
1*/*2 * Created by Hao on 2014/12/28. 3 */ 4 var mongoose = require (' Mongoose '); 5 mongoose.connect (' Mongodb://localhost/newfarmer '); 6 exports.mongoose = Mongoose;
In the models directory, add the Users.js file to the user entity class
1 /**2 * Created by Hao on 2014/12/28.3 */4 varMongoDB = require ('./mongodb '));5 varSchema =Mongodb.mongoose.Schema;6 varUserschema =NewSchema ({7 username:string,8 password:string,9 salt:string,Ten hash:string One }); A varUser = Mongodb.mongoose.model (' users ', Userschema); - varUserdao =function(){}; - theUserDAO.prototype.save =function(obj, callback) { - varInstance =NewUser (obj); -Instance.save (function(err) { - callback (ERR); + }); - }; + AUserDAO.prototype.findByName =function(name, callback) { atUser.findone ({username:name},function(err, obj) { - callback (err, obj); - }); - }; - -Module.exports =NewUserdao ();
Nodejs (i) Simple login verification using mongoose Operation MongoDB