Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use mutable header APIs after sent. #4

Open
Migrate opened this issue Jul 6, 2011 · 0 comments
Open

Can't use mutable header APIs after sent. #4

Migrate opened this issue Jul 6, 2011 · 0 comments

Comments

@Migrate
Copy link

Migrate commented Jul 6, 2011

Hi,

Thanks for writing this great plugin. I'm using it in several collections.

I'm also trying to use mongoose-types in a embedded document, but it does not work: The first sub-document is added without any problems but then I cannot add more sub-documents. I always get the following error:

http.js:543
throw new Error("Can't use mutable header APIs after sent.");

Here is the code:

//add tracker to account.

var Actor = mongoose.model('Actor');
function add_tracker(req, res, next) { 
    Actor.findById(req.params.id, function(err, actor) {
        if (err) {
            console.log(err);
        }
        var tracker_value = req.body.tracker.value;
        var tracker = { value: tracker_value };
        var trackers_size = actor.trackers.length;
        actor.trackers.push(tracker);
        actor.save(function(err){
            res.local("actor", actor);
            if (err) res.send({ error: err.message });
            var tracker = actor.trackers[trackers_size];
            res.partial('account/_tracker', { object: tracker }, function(err, html) {
              if (err) {
                  res.send({ error: err.message });
              } else {
                  res.send({ prepend: html, to: '#tracker_list' });
              }
            });
          })
    });
}

//database schema:

var mongoose = require('mongoose'), 
    mongooseTypes = require("mongoose-types"),
    useTimestamps = mongooseTypes.useTimestamps;

var Trackers = new Schema({
        value : String
 });
Trackers.plugin(useTimestamps);

var Actor = new Schema({
        , name     : String
        , trackers      : [Trackers]
});
mongoose.model('Actor', Actor);

If I remove mongoose-types from the embedded the error does not occur.

Thanks.
Best regards,
Migrate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant