Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8325825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:34:01+00:00 2026-06-09T00:34:01+00:00

since four days I’m trying to figure out how to follow a reference from

  • 0

since four days I’m trying to figure out how to follow a reference from one to another class, starting from the class which is beeing referenced. In SQL-Django there is a related_name to achieve this…

For example I have this class:

class MyClass(Document):
    ...
    other_classes = ListField(ReferenceField(Other_Class))

and this one:

class Other_Class(Document):
    ...

Now I want to go from Other_Class to MyClass… Any ideas?

Thanks,

Ron

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:34:02+00:00Added an answer on June 9, 2026 at 12:34 am

    Here is a test case showing how to query it:

    import unittest
    from mongoengine import *
    
    
    class StackOverFlowTest(unittest.TestCase):
    
        def setUp(self):
            conn = connect(db='mongoenginetest')
    
        def test_one_two_many(self):
    
            class MyClass(Document):
                other_classes = ListField(ReferenceField("OtherClass"))
    
            class OtherClass(Document):
                text = StringField()
    
            MyClass.drop_collection()
            OtherClass.drop_collection()
    
            o1 = OtherClass(text='one').save()
            o2 = OtherClass(text='two').save()
            m = MyClass(other_classes=[o1, o2]).save()
    
            # Lookup MyClass that has o1 in its other_classes
            self.assertEqual(m, MyClass.objects.get(other_classes=o1))
    
            # Lookup MyClass where either o1 or o2 matches
            self.assertEqual(m, MyClass.objects.get(other_classes__in=[o1, o2]))
    

    The main question is do you need to store a list of references in the MyClass? It might be more efficient to store the relationship just on OtherClass..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since this question is back to four votes to close, I'm trying again to
Since I am developing an iOS >= 5.0 application, I am trying to change
Since input and raw_input() stop the program from running anymore, I want to use
I am trying to cast a datastream into a struct since the datastream consists
I have a report in SSRS 2008 that shows data aggregated from four levels
I created an experimental branch from master, and made four commits on the experimental
I am trying to write a function which checks if a Finished Lesson was
since last four years i had been coding in c/c++, but those lenthy programs
I have a swf with four frames. The first frame loads an external class
I have a table with four columns: id, from, to, msg. The rows can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.