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

        var getContent = "this is an example";

        var  theCase = Cases.findOne({ mobileNumber:getPhoneFrom, caseStatus:"open" });

		Cases.update(theCase._id,
			{$set: {
				content: getContent,
				messageStatus:'reply',
				}
			}
		);

The Cases.update simply doesn’t run, the script dies out… but there are no errors reported in the log when running on Galaxy. If I put console.log(‘before’) and an console.log(‘after’) – the after does not run.

So… what the heck?

The query on line 5 needs to be a document, not a string.

@vooteles no correct, this can be a string. Meteor will make a query out of it for you.

@SkyRooms have you checked that the doc exists? do you use a schema? do you use collection2? Maybe those fields are not in the schema, then collection2 would filter them out? wildly guessing here :smiley:

1 Like

Ahhh yes! Good call, I’m using autoform – maybe one of the fields are missing! But wait… on an update I have to include all the fields?

I will check in to that.

And yeah if i console.log(theCase._id); it’s there.

The $set simply STOPS running with no error message. BRB checking!!

I’m so frustrated right now. I have to do updates and Autoform doesn’t return any errors, but I’m confident this is the problem… GRRR.

Issue is also here with a fix that is blowing my mind…

You must specify what theCase._id shall match

Cases.update({_id: theCase._id}, {$set:{…}})

Still not working!

image

Can you console.log(theCase) to see if your findOne returns anything?

theCase is absolutely returned, spits the whole thing out…

image

image

Any error in the server logs?

Nope. Nothing appears to be wrong at all. It simply gets to this $set and stops.

No logs. Nothing.

Is this in the server or on the client? Can you update the document with mongo shell?

This is a server side method, and yeah I can update the document externally.

This guy has solved it? Looking through it now

Woooow look at that, it’s a problem with the schema…

Once I removed the Schema from the Collection it magically works. Shoot me.

OH HELL now the AutoForm wont work. For cyring out loud man.

have you tried to add { validate: false, filter: false } to your update?

Cases.update(theCase._id,
 {$set: {
   content: getContent,
   messageStatus:'reply',
   }
 },{ validate: false, filter: false }
);

I’ve just tried that, no effect, still doesn’t work.

image

I’ve now even tried to strip down the Schema… still bugs out.

image

Finally got some where, reading carefully through these docs:

Books.update(id, {$set: {“borrowedBy.1.name”: “Frank”}});
However, this will not pass validation. Why? Because we don’t know whether item 1 in the borrowedBy array already exists, so we don’t know whether it will have the required email property after the update finishes.

There are three ways to make this work:

$set the entire object
$set all required keys in the object
Perform the update on the server, and pass the validate: false option to skip validation.
When this situation occurs on the client with an autoForm, it generally does not cause any problems because AutoForm is smart enough to $set the entire object; it’s aware of this potential issue. However, this means that you need to ensure that all required properties are represented by an input on the form. In our example, if you want an autoForm that only shows a field for changing the borrowedBy name and not the email, you should include both fields but make the email field hidden. Alternatively, you can submit the autoForm to a server method and then do a server update without validation.

Although these examples focused on an array of objects, sub-objects are treated basically the same way.

So I stripped my schema right down to just caseStatus.

WORKS
Cases.update(theCase._id, {$set: {“caseStatus”: “closed”}});

BREAKS
Cases.update(theCase._id, {$set: {caseStatus: “closed”}});

Notice that finding the selector has to be declared as a string, where as using raw meteor calls you don’t have to.

A simple solution to an insane problem?