0
我希望能夠通過集合迭代,這樣我可以去通過所有對象。這裏是我的架構:最簡單的方法來迭代通過集合在貓鼬
'use strict';
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const bcrypt = require('bcrypt');
const moment = require('moment');
//Create user schema
const UserSchema = new Schema ({
username: { type: String, unique:true },
password: {type:String},
phonenumber: Number,
});
//**************PASSWORD STUFF *******************************
//Hash the password so it becomes encrypted.
UserSchema.methods.generateHash = function(password){
return bcrypt.hashSync(password,bcrypt.genSaltSync(9));
}
UserSchema.methods.validPassword = function(password){
return bcrypt.compareSync(password,this.password);
}
//************************************************************
//Schema model.
const User = mongoose.model('user-dodger', UserSchema);
module.exports = User;
我想現在使用它,我可以進入User.find方法,但它似乎並沒有做任何事情 –
沒關係得到它的工作tyty –