Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var userSchema = new mongoose.Schema({
- firstname: String,
- surname: String,
- email: String,
- });
- var appointmentSchema = new mongoose.Schema({
- userID: String,
- type: Number,
- time: Date
- });
- Appointment.aggregate([
- {
- $match: {"type": 1}
- },
- {
- $lookup:{
- from: "users",
- localField: "userID",
- foreignField: "_id",
- as: "appointmentUser"
- }
- }], function(err,foundAppointmentUser) {
- if(err){
- console.log(err);
- } else {
- console.log(foundAppointmentUser);
- }
- });
- {
- "_id": {
- "$oid": "5bcc8eac7ac5980bfa365183"
- },
- "userID": "5bb4d1945480e60771ccde5a",
- "type": 1,
- "time": {
- "$date": "2018-10-22T10:00:00.000Z"
- },
- "__v": 0
- }
- {
- "_id": {
- "$oid": "5bb4d1945480e60771ccde5a"
- },
- "firstname": "Stu",
- "surname": "Test 999",
- "email": "stu@stu.com",
- "created": {
- "$date": "2018-10-03T14:26:28.815Z"
- },
- "__v": 0
- }
- [ { _id: 5bcc8eac7ac5980bfa365183,
- userID: '5bb4d1945480e60771ccde5a',
- type: 1,
- time: 2018-10-22T10:00:00.000Z,
- __v: 0,
- appointmentUser: [] } ]
Add Comment
Please, Sign In to add comment