Mixed Schema with Array creates always two entries

0 views
Skip to first unread message

Hermann Schliederwirte

unread,
Sep 16, 2014, 5:02:54 AM9/16/14
to mongoos...@googlegroups.com
I have this schema:

var DEMOSCHEMA = new Schema({

    member1:                {},
    member2:                []

});


module.exports = mongoose.model('DEMOSCHEMA', DEMOSCHEMA);

I have this route:

  create = function(req, res) {

    console.log('POST - /ip/create');

    var nowObj = new Date();

    var demoschema = new
DEMOSCHEMA ({
      member1:     req.body.member1,
      member2:    [
                      {
                        date: nowObj,
                        changed: req.body.member2
                      }
                   ]
    });

    demoschema
.markModified('member1');
   
demoschema.markModified('member2');
   
    ip.save(function(err) {

      if(err) {
        console.log(err);
        res.send({ status: err });
        return;

      } else {

        console.log("DEMOSCHEMA created");
        return res.send({ status: 'OK', demoschema:
demoschema });
      }
    });
  };


Now if I call my API the correct entry gets created in Mongo, but also a second entry with no members or values, but with a new ObjectID. I only want one new entry per "create()" call.

What is this and how to not have this? I am seeing this for days now, can't get rid of this bug.
Reply all
Reply to author
Forward
0 new messages