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 8365091
In Process

The Archive Base Latest Questions

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

I have a model Post: class Post(db.Document): created_at = db.DateTimeField(default=datetime.datetime.now, required=True) title = db.StringField(max_length=255,

  • 0

I have a model “Post”:

class Post(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    title = db.StringField(max_length=255, required=True)
    slug = db.StringField(max_length=255, required=True)
    body = db.StringField(required=True)

Assuming I create a post variable with the Post object, but before I save it off I save it to a collection name other than the default (Post) for example:

post._meta['collection'] = "customcollection"
post.save();

Then how do I fetch all the documents in the customcollection with mongoengine?

Normally if I did not set customcollection I could do something like:

for item in Post.objects:
    print item.title

But since I set a customcollection, I want to be able to do something like:

for item in customcollection.objects:
    print item.title

Though I get a:

NameError: global name 'customcollection' is not defined

What do I need to do in syntax to be able to fetch all the Post objects in my customcollection?

  • 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-09T12:34:45+00:00Added an answer on June 9, 2026 at 12:34 pm

    If you want the Post document class to point to customcollection just do this:

    class Post(db.Document):
        created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
        title = db.StringField(max_length=255, required=True)
        slug = db.StringField(max_length=255, required=True)
        body = db.StringField(required=True)
        meta = {'collection': 'customcollection'}
    

    Now when you do:

    for item in Post.objects:
        print item.title
    

    It should read its posts out of the customcollection collection.

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

Sidebar

Related Questions

If I have a model... class Post include Mongoid::Document field :link field :title field
I have this Model in django : class Post(models.Model): title = models.CharField(max_length=255) category =
I have 2 multi-table inherited models like these: class Post(models.Model): title = models.CharField(max_length=100, blank=True,
Assuming i have a post model with created_at, title, and id. How can i
I have in model post.rb : class Post include Mongoid::Document attr_accessible :content, :original_post end
I have the following model: class Entry include Mongoid::Document field :title, type: String field
I have a typical, Post model: class Post< ActiveRecord::Base validates_presence_of :user_id #Line 1 validates_presence_of
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
Hello i'm working on a blog app and I have a model: class Post(models.Model):
in a django-tastypie app I have the following Django-models: class Car(models.Model): name=models.CharField('name',max_length=64) class CarTrack(models.Model):

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.