0

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.

Jor Khachatryan
  • 151
  • 1
  • 3
  • 13
  • Using mongoose with two databases in the same application is [tricky](https://stackoverflow.com/a/19475270/1282674). You should reconsider your approach or if you really need to, you should paste how you connect to the databases and how are the models defined. – drinchev Nov 19 '18 at 11:47
  • Thanks for replying drinchev. I have one database and two collection init and two apps.Both apps connected to that databases.Directories of applications are different too.I need to handle first collection from second app. – Jor Khachatryan Nov 19 '18 at 12:08

0 Answers0