Nodejs (i) Simple login verification using mongoose Operation MongoDB

Source: Internet
Author: User

---restore content starts---

Development using Webstorm 9

New nodejs+express project Newfarmer

Article Directory

    1. Configure Mongoose
    2. Creating Directories and files
    3. Insert data, Post commit JSON add a record
    4. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.