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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:30:29+00:00 2026-05-23T15:30:29+00:00

I am currently exploring the possibilities of the MongoEngine object document mapper. What is

  • 0

I am currently exploring the possibilities of the MongoEngine “object document mapper”. What is currently not clear to me is to what extent I can move my validation and object creation logic to the Document objects themselves.

I have the impression that it should not be a problem, but I’m not finding a lot of examples/caveats/best practices regarding issues as

  • Custom validation functions that are automatically called on save() to evaluate if field contents are valid;
  • Automatic generation of the identifier on save(), based on the hash of the contents of a field;

I think I need to override the save() method, so that I can call my custom logic, but the lack of examples leads me to believe that that may be a wrong approach…

Any examples, or references to high-quality codebases using mongoEngine, are welcome.

  • 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-23T15:30:29+00:00Added an answer on May 23, 2026 at 3:30 pm

    You can override save(), with the usual caveat that you must call the parent class’s method.

    If you find that you want to add validation hooks to all your models, you might consider creating a custom child class of Document something like:

    class MyDocument(mongoengine.Document):
    
        def save(self, *args, **kwargs):
            for hook in self._pre_save_hooks:
                # the callable can raise an exception if
                # it determines that it is inappropriate
                # to save this instance; or it can modify
                # the instance before it is saved
                hook(self):
    
            super(MyDocument, self).save(*args, **kwargs)
    

    You can then define hooks for a given model class in a fairly natural way:

    class SomeModel(MyDocument):
        # fields...
    
        _pre_save_hooks = [
            some_callable,
            another_callable
        ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently exploring the different options for building a not-too-complex web application, in which
I´m currently exploring Prime faces, and I´m wondering how we can validate the selection
I'm currently exploring django forms and have a issue I hope someone can help
I am currently exploring the possibilities of WF. Now i downloaded some sample from
I am currently exploring the specification of the Digital Mars D language, and am
I'm currently exploring the possibility of integrating MYOB Exo Business (Exonet) to a shopping
I'm currently exploring Broadcast Receivers and Broadcast Intent. There are some aspects of the
I'm currently exploring worst case scenarios of atomic commit protocols like 2PC and 3PC
I am currently exploring a bug in the template used on http://www.ecovivo.be/rubriek/food . Problem:
I'm currently exploring interfacing C and R (using R's .Call for speed). I've only

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.