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

  • Home
  • SEARCH
  • 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 6559219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:17:47+00:00 2026-05-25T13:17:47+00:00

If I have these models: class Sub(EmbeddedDocument): name = StringField() class Main(Document): subs =

  • 0

If I have these models:

class Sub(EmbeddedDocument):
    name = StringField()

class Main(Document):
    subs = ListField(EmbeddedDocumentField(Sub))

I want to have a query that returns the Mains, with the subs being filtered by name existing

Main.objects.filter(subs__name__exists=True)

This returns the correct Mains, but the Subs are always the entire list, not a subset. How can I get only the subset? Do I need to rely on list comprehensions?

  • 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-05-25T13:17:48+00:00Added an answer on May 25, 2026 at 1:17 pm

    MongoDB doesn’t support exactly this operation that you’re requesting, and therefore neither does Mongoengine.

    You can perform slicing operations on arrays (lists), but not ad-hoc filtering. Slicing in MongoDB arrays works similarly to slicing lists in Python, and you can do it with Mongoengine using the slice__ keyword syntax:

    Main.objects.filter(subs__name__exists=True).fields(slice__subs=[0,2])
    

    This will return the subs starting at index 0 (i.e. the first element) and returning two elements after that.

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

Sidebar

Related Questions

Greetings, I have these 2 models: from django.db import models class Office(models.Model): name =
I currently have these models: class Category(models.Model): name = models.CharField(max_length=200) parent = models.ForeignKey('self', blank=True,
I have these models: class Client(models.Model): is_provider = models.BooleanField() class Billing(models.Model): client = models.ForeignKey(Client)
I have these two models: class CommonVehicle(models.Model): year = models.ForeignKey(Year) series = models.ForeignKey(Series) engine
Say I have these models class Project < ActiveRecord::Base has_many :comments end class Comment
I have these two models: class Application_Model_List extends Zend_Db_Table_Abstract { protected $_name = 'list';
I have these models: class A(Model): pass class B(Model): the_a = ForeignKey(A) class C(Model):
In Django application I have these models: class DLL(models.Model): prev = models.ForeignKey('self', related_name =
I have some models; Vocabularies (tags lists), Labels (tags) and different articles types. These
I want to generate a list using my django model say I have these

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.