Problem with the $split operation. [Computing Fields-Chapter1-Lab2]

Hey there,

I used $project and $match expressions. I used $split and $size under the $project stage and then I tried to $match single words. But when I execute these commands I’m waiting response from the server. Here is the screenshot:

< deleted >

Hey there again. I’m having a problem with the algorithm I think. I solved out every other syntax problem btw. Now my problem is I’m creating a array of words and create a new area that is array’s size basically.

But looks like my condition works wrong because every size is assigned “NA”.

BTW I’m trying not to post my code but in order to get help you should see the code I think. So I’m adding screenshot for this.

< deleted >

As you can see I tried to use your clarification as a validation point but that also doesn’t work…

< deleted >

@Burak_84129

Unfortunately, posting a screenshot is essentially the same as posting the code, as anyone can see what the code is. So, while I appreciate your attempt to follow the guidelines, please do not post screenshots. Try to explain what you’re doing without going into detail of the code. Thanks.

I tried to $split titles into array of strings, then I tried to find out the sizes of those arrays are actually arrays. Then assign size information to a new field. While I’m doing that I also wrote a condition that check if arrays are actually arrays then assign size if not assign NA value.

But all I got is NA. Problem looks like $split splits arrays correctly but this new field of arrays can’t be used inside of $size.

So I’m posting ONLY my results not the codes.

Ok I found out the problem. I was referring to array that created in the same stage of pipeline, so I divided my pipeline into 2 then I was able to see word counts correctly! Then I used match operation to see titles with 1 words.

1 Like

Use split inside the project and assign that to a variable which is an array
something like {$project:{“newTitle”:{$split…
then use match array size =1
something like this {$match:{newTitle .size =1}

Yes, that’s exatcly how I done it :slight_smile:

But there was a problem when you use “$array” referring in the same stage. So I split in first stage, then assigned the size in another stage. After that I filtered out the size in match

yes you right, it has two stages
stage 1 is project
when I said array what I meant the split output is array.

in the match stage you should use size against the new array from stage 1

if this doesn’t work inbox me privately

we can discuss more

I’m having some problems solving this lab, can somebody help me a little?
I’m getting this error:

“not authorized on mflix to execute command { aggregate: “movies”, pipeline: [ …”

Thanks!

@Guillem_40013

It does not appear that you’re having a problem with $split? If not, then please open a new post with your specific problem. If so, then explain what exactly your $split problem is. Thanks.

Yes, it’s when I run the whole pipeline with the project, and then I try to do the match on the results. But it’s hard to explain the problem without giving a potential answer… Could you send me a PM, I’ll show you the code and maybe you can tell me what I am doing wrong? Thank you DHz

@Guillem_40013
;
The error you report would indicate that you cannot access the the collection ‘mflix’ which is not part of our database in any case and not connected to the $split command. And I would appeciate it if you would follow my directions and post this as a new thread. Then I can try to help. Thanks.

You are completely right, I was using the database from another course, which also had movies… Sorry.
After some work on it I managed to get the correct answer. Thanks!