We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to deal with embedded document of mongodb ?

I have a mongodb collection like image below, and I want to perform operations like sort, shift, limit .etc within the array circled by red. Mongodb support these operations by its shell script although it's an embedded document. How can I implement this in phalcon ? Or is there any way I can execute Mongo scripts in phalcon? Thanks sincerely!



98.9k

Try:

MyModel::find(array(
    'conditions' => array(
        'time' => array($compare => $time)),
    'sort' => array('bookmark.document.time' => -1),
    'limit' => $count
));


2.1k

Thank you! Phalcon. I've tried but it still can't work. I think maybe it's because the "bookmark.document" is an array, and it has elements from 0--6, so when we sort it by "bookmark.document.time" , phalcon can't understand what I mean. neither the condition can work, when I wrote code

'conditions' => array( '_id' => $userId 'bookmark.document.time' => array('gt' => $time) )

it returns nothing. So what should I try next?