Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const UsersSchema = Schema({
- name: String,
- email: {type: String, unique: true, lowercase: true},
- password: {type: String, select: false},
- created: {type: Date, default: Date.now()},
- });
- module.exports = mongoose.model('User', UsersSchema);
- const ReferralsSchema = Schema({
- image: String,
- userId: {type: String, select: false},
- created: {type: Date, default: Date.now()}
- });
- module.exports = mongoose.model('Image', ImageSchema);
- ImageSchema.aggregate()
- .lookup(
- { from: 'users', localField: 'userId', foreignField: '_id', as: 'user' }
- )
- .exec( (err, images) => {
- console.log(err,images);
- })
- { _id: 5b0ed0a671dd9a3c7ac115f5,
- image: 'testigimage.png',
- userId: '5aa97c526fc4e7108738e8c1',
- __v: 0,
- user: [] } ]
Add Comment
Please, Sign In to add comment