Lookup and sort [Solved]

I have problems and I get stuck with the facets.

I create a to make a lookup and a sort, but it’s not working and I couldn’t test in Compass neither (I’ve always get a syntax error but I’m copyng the example of the lecture!!!".

Hi @Daniela_Galigniana_87574

Firstly you don’t need to copy or replicate the lectures, we only ask students to follow the lab sessions. In terms of your specific problem, can you provide the error and related screenshots to help understand what the specific issue is?

Kindest regards,
Eoin

Thank you for the response.
I’m following the labs, as it is requested.

As I was stuck, I’ve tried to copy the lecture example to discover the problem. I’ve finally got the facets to work.

Bus I’m still stuck with the GetComment ticket. After the lookup I’m not able to sort the comments by date.

I’ve tried a lot of combinations during the last 5 days and I can’t resolve it.

The following should help you.

https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/
https://docs.mongodb.com/manual/reference/operator/aggregation/group/
https://docs.mongodb.com/manual/reference/operator/aggregation/push/

1 Like

Hi @Daniela_Galigniana_87574

I think that @steevej-1495 has given some very useful suggestions in his comment (Lookup and sort). These should help you and thank you Steeve!

Eoin

Thanks @steevej-1495 and @brazileoin but clearly I’m blocked. I can no resolve in the Java code.
I can do it in Compass, but the Java code generated there I cannot use in my environment, because the methods are different.

I will continue trying for a couple of hours to try to finish it, otherwise I will give up :frowning:

Hi @Daniela_Galigniana_87574

I’d take a look at the MongoDB Java Driver page on aggregation, specifically the sort section to see if it helps (http://mongodb.github.io/mongo-java-driver/3.1/builders/aggregation/ ).

Hope this helps!
Eoin

Thank you @brazileoin and @steevej-1495 for the information but I give up.
I cannot resolve the lookup. I don’t know why, but all the documentation is different of what I have in my environment and nothing works.

I’ve tried a pipeline with match, lookup, unwind, sort, group but the comments are in a nested array.
The push, that is defined in Updates.push I can not create to add. So, after a week working with it, I give up.

Anyone knows if the correct response is shown at the end of the course?

Regards

Hello @Daniela_Galigniana_87574 , Even i tried for two full days but somehow found the proper solution.
The trick is , i converted the Compass Query into set of Documents like , new Document("##", new Document("$$$", “@@@@”).append(“", new Document("%%%", "”)) and so on…

Cheers,
Vinodh Kumar T

Thanks @vinodh5052 but I’m so blocked that nothing work for me.

Now I get an exception, with and error code 40234 ‘The field ‘$push’ must be an accumulator object’

@Daniela_Galigniana_87574, is your query executing in compass? I’m afraid that we don’t need any $push operation in $lookup.
We need $match for join and $sort in descending.

Yes, it’s executing. In the Java Driver I was unable to use the lookup with variables and pipelines.
The compiler says it not found the method, altough I see it in the libraries!!

@Daniela_Galigniana_87574; Is there any other place we can discuss about this? We are not supposed to paste queries or solutions in discussion forums.
I use only Twitter @vinodh_5052; may be we can discuss if necessary.

Thanks @vinodh5052. My Twitter is @dakgma

I also had an issue with these both tickets and finally, changing sort help me.
But i did it, not in correct way by my opinion.
I wanted to execute only one query to MongoDB to get one document, with a comments array. But instead i did two. So in the beginning, i tried to execute lookup with additional pipeline, and in scope of it use sort. But no any my attempts finished successfully. Can you help me with that? i really want to implement solution with only one query. So i dont want to post code there

Hi @Illia_50701

Can you clarify if you are able to pass the testing phase and get the verification code ? I just want to understand whether this is blocking your progress on the course or whether you are just interested in a general / more efficient solution.

Kindest regards,
Eoin

Hi, Sorry for the long response. Yes i got both verification codes. I just interesting how i can do it in more elegant and proficient way. Could you please assist or consult me ?

Hi @Illia_50701

Thanks for the clarification, I think you would be better to post that question to the MongoDB User Group on Google Groups at http://groups.google.com/group/mongodb-user . Then you will be able to post all the code and get feedback with reference to the code examples which isn’t possible in these forums.

Hope this helps!
Eoin

Thank you everyone.
Althought the due date, I’ve finally get the lookup running.
I will continue with the rest of the tickets and try to catch up.

1 Like