Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Filter data before lookup(join) two collections in mongodb

Filter data before lookup(join) two collections in mongodb

Scheduled Pinned Locked Moved The Lounge
databasemongodbregexquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 8 Offline
    8 Offline
    855
    wrote on last edited by
    #1

    I'm writing a function which will join two collections and two filters for each.

    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?

    P OriginalGriffO R 3 Replies Last reply
    0
    • 8 855

      I'm writing a function which will join two collections and two filters for each.

      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?

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      Step one: Refer to the red link at the top of this page.

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      1 Reply Last reply
      0
      • 8 855

        I'm writing a function which will join two collections and two filters for each.

        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?

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Teachers shouldn't lookup students. You end up on all sorts of Registers if you do that, as well as being banned from teaching.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • 8 855

          I'm writing a function which will join two collections and two filters for each.

          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?

          R Offline
          R Offline
          Richard Deeming
          wrote on last edited by
          #4

          So you posted this in QA[^]; reposted it in the database forum[^]; and now you've posted a third copy in the forum which explicitly forbids programming questions. Your impatience and inability to follow the rules clearly know no bounds. :doh:


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups