GithubHelp home page GithubHelp logo

Comments (7)

jacqueswaller avatar jacqueswaller commented on July 19, 2024 1

I've run into the same problems where my old method of "just type what I want to do into Google" always explains how to do it with the old driver.

I have found the API to be useful though: http://mongodb.github.io/mongo-php-library/api/namespace-MongoDB.html

In particular the Client and Collection classes. There's no plainly written examples but having written a lot of code with the old driver I was able to figure stuff out. So yes, as you've noticed find and findOne return different results (this was true with the old driver as well). From the documentation, findOne returns an object or null. find returns a MongoDB\Driver\Cursor. The php library is just a wrapper around the low-level MongoDB driver, so for more information on the driver classes (like MongoDB\Driver\Cursor) you'll want to go here http://php.net/manual/en/set.mongodb.php

from mongo-php-library.

p-golovin avatar p-golovin commented on July 19, 2024 1

I have a problem with deserialisation.

Create client with typemap option:

new \MongoDB\Client("mongodb://".implode(",", $config['server']), $opts, ['typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array']]);

But

                $mongo_list = $log_collection->distinct("context.user");
                var_dump($mongo_list);

returns me array of objects:

array (size=193)
  0 => 
    object(stdClass)[48]
      public 'login' => string '...' (length=4)
  1 => 
    object(stdClass)[50]
      public 'id' => int 527
      public 'name' => string '...' (length=25)
      public 'login' => string '...' (length=4)

from mongo-php-library.

elfeffe avatar elfeffe commented on July 19, 2024

I found https://github.com/mongolab/mongodb-driver-examples/blob/master/php/php_simple_example.php
Which helps, but sort doesn't work.

There is no documentation over the whole Internet

from mongo-php-library.

elfeffe avatar elfeffe commented on July 19, 2024

To collaborate with the documentation:
This is how options (sort, limit) works
http://stackoverflow.com/questions/35147845/how-does-sorting-work-in-the-new-mongodb-pecl-extension

It took more than 2 days to find the way. I hope it helps someone.

from mongo-php-library.

elfeffe avatar elfeffe commented on July 19, 2024

Thank you @jacqueswaller

from mongo-php-library.

jacqueswaller avatar jacqueswaller commented on July 19, 2024

I don't have the driver installed atm to test so I can't say for sure, but looking at the API I think that
Distinct::execute could stand to have

if (isset($this->options['typeMap'])) {
    $cursor->setTypeMap($this->options['typeMap']);
}

the same way that Find::execute does.

from mongo-php-library.

jmikola avatar jmikola commented on July 19, 2024

@elfeffe: Glad you got this sorted out. The prose-style documentation still needs a bit of love, so the API documentation that @jacqueswaller suggested is definitely worth looking at. As a general rule, most of the Collection and Database methods use an Operation class, where we've documented all of the options in the constructor. Of course, I still need to port that over to the prose documentation, since users shouldn't be expected to poke around generated API docs for such basic info.


@p-golovin: We can't support a typeMap option for command helpers until PHPC-314 is implemented. The reason being is that type maps are currently limited to root and embedded documents, and since the non-cursor commands (e.g. distinct, findAndModify) return results within a sub-field (e.g. a results array of objects), we have no way to tell the driver to apply the type map starting with those results, which is undoubtedly what users would expect. The PHPLIB tracking ticket for this is PHPLIB-112.

In the future, please open a new issue unless your question is identical to the OP. That will ensure we don't lose track of things and make it easier for other folks to follow conversation or dig up the question/answer down the line.

from mongo-php-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.