You can convert the mongo shell query to search into a mongoid query like this. It hurt me to figure it out. So send here if this helps someone.
clookup = {
'$lookup': {
'from': "contacts",
'localField': "_id",
'foreignField': "account_id",
'as': "contacts"
}
}
sort = { '$sort': { '_id.year': 1, '_id.month': 1 } }
docs = Account.collection.aggregate([clookup, sort])
pp docs.first
source
share