mongo-php-library icon indicating copy to clipboard operation
mongo-php-library copied to clipboard

How to use limit and skip feature?

Open SendOTP opened this issue 11 years ago • 4 comments

Hi, I had gone through the api documentation http://mongodb.github.io/mongo-php-library/api/class-MongoDB.Client.html but I can't find any details for mongodb limit, skip, sort API's. These basic API are used many times in my application and as I am shifting the whole code to HHVM I need this. Any help would be really appreciated.

Thanks in advance :)

SendOTP avatar Oct 30 '15 14:10 SendOTP

There are no helper methods for these arguments (other then findOne(), to limit=1).

You'll have to pass it as an argument to the find method, see:

<?php
use MongoDB\Client;
use MongoDB\Collection;

$client = new Client("mongodb://localhost:27017");
$collection = new Collection($client, "databaseName.collectionName");
$query = array("zipcode" => "90210");
$queryOptions = array("limit" => 1);

$result = $collection->find($query, $queryOptions);
?>

bjori avatar Oct 30 '15 16:10 bjori

@waterone: My apologies for the difficulty with the API docs. We certainly plan to get more tutorial-style documentation added soon.

For now, if you peak at the methods in the Collection class, you'll see that most point to an Operation class, which is where you'll find any supported options documented (ultimately, we'll get this over to real documentation outside of the code). You can check out src/Operation/Find.php for the various find options, which should match those outlined in our cross-driver CRUD specification.

jmikola avatar Oct 30 '15 16:10 jmikola

The best docs on this I can find at the moment is: http://mongodb.github.io/mongo-php-library/api/source-class-MongoDB.Operation.Find.html#32

You are welcome to file a documentation ticket asking for better examples in our JIRA. Docs are currently our highest priority so it is perfect timing to raise issues like this.

Our general tracking tickets for all things docs is: https://jira.mongodb.org/browse/PHPC-289

bjori avatar Oct 30 '15 16:10 bjori

Yes surely I will raise a ticket for this. Thanks for the help. If any other input is needed from my side feel free to contact me.

Thanks again :)

On Fri, Oct 30, 2015 at 9:48 PM, Hannes Magnusson [email protected] wrote:

The best docs on this I can find at the moment is: http://mongodb.github.io/mongo-php-library/api/source-class-MongoDB.Operation.Find.html#32

You are welcome to file a documentation ticket asking for better examples in our JIRA. Docs are currently our highest priority so it is perfect timing to raise issues like this.

Our general tracking tickets for all things docs is: https://jira.mongodb.org/browse/PHPC-289

— Reply to this email directly or view it on GitHub https://github.com/mongodb/mongo-php-library/issues/40#issuecomment-152571801 .

Best, Sameer Rathod Full Stack Developer +91-8109413462 "Honor is something that all men are born with. It cannot be taken from you nor can it be granted. It must only not be lost."

UtterU http://utteru.com| MSG91 | http://msg91.com SendOTP http://sendotp.com

SendOTP avatar Oct 31 '15 05:10 SendOTP