Guest User

Untitled

a guest
Jun 8th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. const UsersSchema = Schema({
  2. name: String,
  3. email: {type: String, unique: true, lowercase: true},
  4. password: {type: String, select: false},
  5. created: {type: Date, default: Date.now()},
  6. });
  7. module.exports = mongoose.model('User', UsersSchema);
  8.  
  9. const ReferralsSchema = Schema({
  10. image: String,
  11. userId: {type: String, select: false},
  12. created: {type: Date, default: Date.now()}
  13. });
  14. module.exports = mongoose.model('Image', ImageSchema);
  15.  
  16. ImageSchema.aggregate()
  17. .lookup(
  18. { from: 'users', localField: 'userId', foreignField: '_id', as: 'user' }
  19. )
  20. .exec( (err, images) => {
  21. console.log(err,images);
  22. })
  23.  
  24. { _id: 5b0ed0a671dd9a3c7ac115f5,
  25. image: 'testigimage.png',
  26. userId: '5aa97c526fc4e7108738e8c1',
  27. __v: 0,
  28. user: [] } ]
Add Comment
Please, Sign In to add comment