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

Plugin won't work on subschemas #8

Open
oscarrc opened this issue Feb 14, 2018 · 1 comment
Open

Plugin won't work on subschemas #8

oscarrc opened this issue Feb 14, 2018 · 1 comment

Comments

@oscarrc
Copy link

oscarrc commented Feb 14, 2018

Let the following schemas

var mongoose = require('mongoose');
var sequenceGenerator = require('mongoose-sequence-plugin');
var Schema = mongoose.Schema;

var childSchema= Schema({
    childID: String,
   someField: String
});

var parentSchema = Schema({
    parentID: String
    children: [childSchema]
});

childSchema.plugin(sequenceGenerator, {
     field: 'childID',
     startAt: '0'
});

parentSchema.plugin(sequenceGenerator, {
     field: 'parentID',
     startAt: '0'
});

I want to push subdocoments to children by doing:

this.findOneAndUpdate({parentID: id}, {$push: {children: {$each: childrenData}}, { new: true, runValidators:true }, function (error, data) {
   //
});

This way no childID is generated in pushed subdocuments.

@kasongoyo
Copy link
Owner

The current implementation does not support subschema but if I will get few hours this weekend I can try to add the support for subschema otherwise I invite the PR @oscarrc

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

2 participants