Wednesday, 7 June 2017

Lookup with array field in mongo db

I have following schema

**User Schema**
const Users = new Schema({
    sFullName: {
        type: String
    },
    sUsername: {
        type: String
    },
    sEmail: {
        type: String
    },
    sPassword: {
        type: String
    }   
    ], 
});

**Album Schema:**

const Album = new Schema({
    sAlbumName: { type: String },    
    sUserId: {type: mongoose.Schema.Types.ObjectId, ref: 'users' },
    myMedia: [{
        sMediaUserId: {type: mongoose.Schema.Types.ObjectId, ref: 'users' },
        sMediaName: { type: String },
        sMediaURL: { type: String },      

        dMediaUpdateDate: {
            type: Date,
            default: Date.now
        } 
    }]      
});

I want to latest 3 user list with uploaded 4 latest media with album title. media will store in myMedia array field.


via Milan Pansuriya

No comments:

Post a Comment