0

I have a mongo database and I'm trying to write an Eloquent code to change some fields before using them in WHERE or ORDER BY clauses. something like this SQL query:

Select ag.*, ht.* 
from agency as ag inner join hotel as ht on ag.hotel_id = ht.id 
Where ht.title = 'OrangeHotel'

-- or --

Select ag.*, ht.* 
from agency as ag inner join hotel as ht on ag.hotel_id = ht.id 
Order by ht.title

sometimes there is no other table and I just need to use calculated field in Where or Order By clause:

Select *
from agency
Where func(agency_admin) = 'testAdmin'

Select *
from agency 
Order by func(agency_admin)

where func() is my custom function.

any suggestion?

and I have read Laravel 4/5, order by a foreign column for half of my problem, but I don't know how can I use it.

Community
  • 1
  • 1
Armin.G
  • 381
  • 2
  • 12

1 Answers1

0

For the first query: mongodb only support "join" partially with the aggregation pipeline, which limits your aggregation in one collection. For "join"s between different collections/tables, just select from collections one by one, first the one containing the "where" field, then the one who should "join" with the former, and so on.

The second question just puzzled me for some minutes until I see this question and realized it's the same as your first question: sort the collection containing your sort field and retrive some data, then go to another.

For the 3rd question, this question should serve you well.

Community
  • 1
  • 1
JJPandari
  • 3,454
  • 1
  • 17
  • 24