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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:02:20+00:00 2026-06-16T21:02:20+00:00

I have a pre-save method defined when saving a document, as follows: Org.pre(save,function(next, done)

  • 0

I have a pre-save method defined when saving a document, as follows:

Org.pre("save",function(next, done) {
  var Currency = require('./currency');

  var cur = this.get('currency');
  console.log("checking currency: " + cur);

  Currency
    .findOne({name: cur})
    .select('-_id name')
    .exec(function (err, currency) {
      if (err) done(err);
      if (!currency) done(new Error("The currency you selected ('" + currency + "') is not supported.  Please select one from /currencies"));
      next();
    });
});

This method checks the currencies collection to see if the currency field input is supported. In testing my API, I get the appropriate error returned (500 error with the message: The currency you selected…), but the document is still saved in MongoDB. I would expect that when an error is sent the document should not be saved. Am I missing something here?

  • 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-16T21:02:21+00:00Added an answer on June 16, 2026 at 9:02 pm

    You’re still calling next(); in the error case, so try rewriting that part as:

    Currency
      .findOne({name: cur})
      .select('-_id name')
      .exec(function (err, currency) {
        if (err) return done(err);
        if (!currency) return done(new Error("The currency you selected ('" + currency + "') is not supported.  Please select one from /currencies"));
        next();
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I could understood that Desktop applications in Java doesn't have a pre-defined relative path
I have a model: class MyModel(models.Model): ... def save(self): print saving ... def delete(self):
I have done some pre processing for dft , and i am trying to
I have a User Model (pre-defined by Django) and a UserProfile model connected via
I have two models in Django: User (pre-defined by Django) and UserProfile. The two
I have a Linq-to-SQL class, and I'd like to perform some pre-save validation before
I have a pre-save signal listener that updates a second model. The same as
I have a lot of pre-existing BMPs (and our clients have pre-existing bmps as
I have a pre tag within my page that contains quite a bit of
I have a pre-made SQLite database that I am downloading from the net via

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.