In my database I have two collections admins and users.I'm using them from different express apps.Both apps connected to the same database.Now I need to fetch all users list from admin app. Here is my User model.
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const config = require('../configs/config');
const uuid = require('uuid/v4');
// User Schema
const UserSchema = mongoose.Schema ({
email: {type: String,required: true,unique:true},
password: {type: String,required: true,unique:true},
created_at:{type:Date,default:Date.now()},
updated_token:{type:String,default:null,unique:true},
deleted:{type:Boolean,default:false},
activation_Token:{type:String,default:null},
isActive:{type:Boolean,default:false}
});
const User = module.exports = mongoose.model('User', UserSchema);
module.exports.getUserById = function(id, callback) {
User.findById(id, callback);
}
module.exports.getUserByEmail = function(email, callback) {
const query = {email}
User.findOne(query, callback);
}
In my admin app I use Uesr.find() function and it doesn't make any sense.Models are in different paths and I dont think that its can bring troubles.Also I'm using nginx web server for proxy-passing.