Computing Fields

I get the split, size concepts of the lab. My problem is a variable that I declare in the project stage, I can’t reference in other stages (ReferenceError: titleArr is not defined ). Can someone please help me understand how I can do this.

Thanks in advance.

@Sheldon_O_Reilly_54245

Normally we’d prefer that you don’t post code, but in this case would you post just the two lines – the pipeline stage where you define the variable and the one where you reference it? Then we’ll try to help. Thanks and good luck.

Thank you for replying. Actually I finally got it working. But … now that i have your attention :slight_smile: I’m also having troubles in Lab Using Cursor-like Stages. I realize I can’t post code but the problem is in my $project stage, I get the following:

Mongo Server error (MongoCommandException): Command failed with error 16410 (Location16410): 'Invalid project :: caused by :: FieldPath field names may not start with '‘.’ on server cluster0-shard-00-00-jxeqq.mongodb.net:27017.

I’ve tried multiple combinations of this, for ex. $num_Favs, “$num_Favs”, num_Favs, “num_Favs”. Same thing with the ‘cast’ array. I assume ’ FieldPath field names ’ are referring to names in doc (I realize num_favs isn’t in doc) and not aggregation expressions. I’ve of course googled but again no luck. Any ideas?

Again Thanks.

@Sheldon_O_Reilly_54245

Two points: first of all, you don’t have to do anything special to “get my attention” – that’s what I"m here for. And, by tacking a new issue onto an older post, you’ve sort of eliminated any help Forum community can give you. So you might want to reconsider how you post this.

Second, I’d suggest that you break your aggregation pipeline down into sections and test each one independently. And notice that the new field should be ‘num_favs’ – no caps or camel case.If you simplify your pipeline, my guess is that you’ll find your problem, which probably isn’t really with your variable name. Good luck.