Click here to Skip to main content
15,881,600 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Sound of the Week Pin
David O'Neil16-Mar-22 7:01
professionalDavid O'Neil16-Mar-22 7:01 
GeneralRe: Sound of the Week Pin
Sander Rossel16-Mar-22 23:10
professionalSander Rossel16-Mar-22 23:10 
GeneralRe: Sound of the Week Pin
David O'Neil17-Mar-22 19:17
professionalDavid O'Neil17-Mar-22 19:17 
GeneralRe: Sound of the Week Pin
Sander Rossel17-Mar-22 22:59
professionalSander Rossel17-Mar-22 22:59 
GeneralRe: Sound of the Week Pin
David O'Neil18-Mar-22 11:46
professionalDavid O'Neil18-Mar-22 11:46 
GeneralRe: Sound of the Week Pin
peterkmx11-Mar-22 11:43
professionalpeterkmx11-Mar-22 11:43 
GeneralRe: Sound of the Week Pin
Sander Rossel11-Mar-22 22:02
professionalSander Rossel11-Mar-22 22:02 
QuestionFilter data before lookup(join) two collections in mongodb Pin
85510-Mar-22 16:36
85510-Mar-22 16:36 
I'm writing a function which will join two collections and two filters for each.
C#
public class Teacher
{
        public string Id{ get; set; }
        public string Name{ get; set; }
        public string TeacherFilter{ get; set; }
        ...
}

public class Student
{
        public string Id{ get; set; }
        public string Name{ get; set; }
        public string StudentFilter{ get; set; }
        public string TeacherId{ get; set; }
        ...
}

public class TeacherStudents
{
        public string Id{ get; set; } -- from teacher
        public string Name{ get; set; } -- from teacher
        public IEnumerable<Student> Students{get;set;}
}

public class TeacherStudents
{
        public string Id{ get; set; } -- from teacher
        public string Name{ get; set; } -- from teacher
        public IEnumerable<Student> Student{get;set;}
}

public class TeacherStudent
{
        public string Id{ get; set; } -- from teacher
        public string Name{ get; set; } -- from teacher
        ...
        public Student Student{get;set;}
}

Get(string TeacherFilter,string StudentFilter).


Here is how i implement it
var query = teacherCollection.Aggregate().Match(x => x.TeacherFilter== TeacherFilter); //filter teach
var query1 = query
.Lookup<Teacher, Student, TeacherStudent>(studentCollection, t => t.Id, s => s.TeacherId, l => l.Student)
.Unwind(x => x.Student, new AggregateUnwindOptions<TeacherStudent>())
.Match(x => x.StudentFilter== StudentFilter) //filter student   

For the teacher collection, useless data has been filter out before lookup which will reduce the data size when doing the lookup(join). But for the student collection, the match stage is appended after the lookup. so does all the data from student will join with teacher behind the scenes? is it possible to filter out some student data before the lookup?
AnswerRe: Filter data before lookup(join) two collections in mongodb Pin
Peter_in_278010-Mar-22 16:44
professionalPeter_in_278010-Mar-22 16:44 
AnswerRe: Filter data before lookup(join) two collections in mongodb Pin
OriginalGriff10-Mar-22 20:18
mveOriginalGriff10-Mar-22 20:18 
RantRe: Filter data before lookup(join) two collections in mongodb Pin
Richard Deeming10-Mar-22 21:01
mveRichard Deeming10-Mar-22 21:01 
Generalthere's nothing more satisfying in coding than solid design Pin
honey the codewitch10-Mar-22 12:56
mvahoney the codewitch10-Mar-22 12:56 
GeneralRe: there's nothing more satisfying in coding than solid design Pin
jmaida10-Mar-22 14:23
jmaida10-Mar-22 14:23 
GeneralRe: there's nothing more satisfying in coding than solid design Pin
Gary R. Wheeler10-Mar-22 14:30
Gary R. Wheeler10-Mar-22 14:30 
GeneralRe: there's nothing more satisfying in coding than solid design Pin
David O'Neil10-Mar-22 15:21
professionalDavid O'Neil10-Mar-22 15:21 
Generalold code PinPopular
honey the codewitch10-Mar-22 6:39
mvahoney the codewitch10-Mar-22 6:39 
GeneralRe: old code Pin
PIEBALDconsult10-Mar-22 6:49
mvePIEBALDconsult10-Mar-22 6:49 
GeneralRe: old code PinPopular
honey the codewitch10-Mar-22 7:12
mvahoney the codewitch10-Mar-22 7:12 
GeneralRe: old code Pin
PIEBALDconsult10-Mar-22 7:21
mvePIEBALDconsult10-Mar-22 7:21 
GeneralRe: old code Pin
DRHuff11-Mar-22 13:55
DRHuff11-Mar-22 13:55 
GeneralRe: old code Pin
Greg Utas10-Mar-22 6:50
professionalGreg Utas10-Mar-22 6:50 
GeneralRe: old code Pin
honey the codewitch10-Mar-22 7:10
mvahoney the codewitch10-Mar-22 7:10 
GeneralRe: old code Pin
Greg Utas10-Mar-22 7:12
professionalGreg Utas10-Mar-22 7:12 
GeneralRe: old code Pin
honey the codewitch10-Mar-22 7:18
mvahoney the codewitch10-Mar-22 7:18 
GeneralRe: old code Pin
jmaida10-Mar-22 11:51
jmaida10-Mar-22 11:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.