Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.03k stars 108 forks source link

Error: Please fill in all required fields during Migrations #376

Closed kjrhody closed 6 years ago

kjrhody commented 6 years ago

I have the following code in a migrations file to update a status of a particular item in a collection. However when the migration runs, I get the following error, despite having the value in the schema and having the field as optional:

Error:

I20180319-09:54:19.193(-4) (percolate_migrations.js:106) Migrations: Running up() on version 7 (Change Photo copyright status of N/A to blank)
W20180319-09:54:19.203(-4)? (STDERR) ~/.meteor/packages/meteor-tool/.1.5.2.xayfcy++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
W20180319-09:54:19.204(-4)? (STDERR)                        throw(ex);
W20180319-09:54:19.205(-4)? (STDERR)                        ^
W20180319-09:54:19.206(-4)? (STDERR) 
W20180319-09:54:19.207(-4)? (STDERR) Error: Please fill in all required fields.
W20180319-09:54:19.208(-4)? (STDERR)     at getErrorObject (packages/aldeed_collection2-core.js:480:15)
W20180319-09:54:19.209(-4)? (STDERR)     at [object Object].doValidate (packages/aldeed_collection2-core.js:462:13)
W20180319-09:54:19.210(-4)? (STDERR)     at [object Object].Mongo.Collection.(anonymous function) [as update] (packages/aldeed_collection2-core.js:214:25)
W20180319-09:54:19.211(-4)? (STDERR)     at Object.Migrations.add.up (server/migrations.js:69:16)
W20180319-09:54:19.212(-4)? (STDERR)     at migrate (packages/percolate_migrations.js:233:25)
W20180319-09:54:19.213(-4)? (STDERR)     at Object.Migrations._migrateTo (packages/percolate_migrations.js:253:7)
W20180319-09:54:19.213(-4)? (STDERR)     at Object.Migrations.migrateTo (packages/percolate_migrations.js:167:10)
W20180319-09:54:19.214(-4)? (STDERR)     at server/migrations.js:77:16
W20180319-09:54:19.215(-4)? (STDERR)     at Function.time (/Users/kjohnson/workspace_gdas/gdas/.meteor/local/build/programs/server/profile.js:309:28)
W20180319-09:54:19.215(-4)? (STDERR)     at ~/.meteor/local/build/programs/server/boot.js:347:13
=> Exited with code: 1

Code: migrations.js:

Migrations.add({
    version: 7,
    name: 'Change Photo copyright status of N/A to blank',
    up: function() {
        Photos.update({copyrightStatus: 'N/A'}, {$set: {copyrightStatus: '' }}, {multi: true});
    },
    down: function() {
        Photos.update({copyrightStatus: ''}, {$set: {copyrightStatus: 'N/A' }}, {multi: true});
    }
});

schema:

    copyrightStatus: {
        type: String,
        label: 'Copyright Permission Status:',
        allowedValues: ['Not Needed', 'Needed', 'Requested', 'Denied', 'Obtained', ''],
        optional: true
    },
kjrhody commented 6 years ago

It appears that the following code was needed in for userId in the schema, since in other cases that had been null when it was the server rather than user running the update:

userId: {
        type: String,
        autoValue: function(){
            if (this.userId === null){
                return "server";
            }
            else{
                return this.userId;
            }
        }
    },