Weird problem -- $set doesn't run, no error?

Firstly

I’m not sure what exactly the problem is caused by here… A reproduction or maybe even just your schema definition could go a long way to help.

Beyond That…

If the issue you are facing is truly the one specified there, then I would recommend flattening your schema a bit by denormalizing your data. Seeing the output of the one case to the console, I don’t think this is the problem.

Lastly

You might try using models for these types of operations. Here is an example using BaseModel from socialize:base-model

import { Mongo } from 'meteor/mongo';
import { BaseModel } from 'meteor/socialize:base-model';
import SimpleSchema from 'simpl-schema';

const Cases = new Mongo.Collection('cases');

const CaseSchema = new SimpleSchema({
    caseStatus: {
        type: String,
        label: 'Case Status'
        optional: true,
        defaultValue: "open",
    },
    // The rest of your schema definition here
});

Cases.attachSchema(CaseSchema);

export class Case extends BaseModel {
    // methods can go here, but are optional
}

Case.attachCollection(Cases);

Once you have your new Case class then you can use it’s methods to manipulate your data…

// Get a case, an instance of Case class will be returned here
const case = Cases.findOne();

// Modify the fields you wish to update here
case.caseStatus = 'closed';
case.content = 'This is a test of case content';

// Now we just save the case by calling it's save() method
case.save();
1 Like

THIS is what has caused the major problem:

ownerId:{
	type: String,
	optional:true,
	autoform: {
		defaultValue: function() {
      		return Meteor.user()._id;
    	},
	},
	autoValue: function() {
        return Meteor.user()._id;
    }
},

Oh hey, is this code from your package? This… simplifies things so much.

I would definitely rework this… For example, the userId field for models in the socialize packages are defined like so…

userId: {
    type: String,
    regEx: SimpleSchema.RegEx.Id,
    autoValue() {
         if (this.isInsert && (!this.isFromTrustedCode || !this.isSet)) {
            return this.userId;
        }
            return undefined;
        },
    index: 1,
    denyUpdate: true,
},

Yes, the returning of models from find/findOne and the save method attached to that model is functionality provided by extending the BaseModel class. There are other packages that provide similar functionality, but I’m obviously very biased :stuck_out_tongue:.

1 Like

You’re right to be biased. It’s a much more simplified approach to collections. Why isn’t autoform and your base package… standard?

Seriously. It should be out of the box.

I took a crack at installing it, but failed, need to mess with some stuff and I will implement over the weekend.

My new launch is https://FaverCRM.com – I have a client meeting next Monday, I’ll sign your Patreon when my client jumps on board. You’re doing Gods work.

1 Like

The simple answer to this is choice… There are other packages out there to choose from and I’m personally happy to not be locked into any one of them… I personally chose to build my preferred workflow around other packages like simpl-schema/collection2/collection-hooks/publish-composite but there is also Astronomy which is an all in one solution that does the same things just put into a single package.