Comments (7)
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.
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.
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.
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.
Thank you @jacqueswaller
from mongo-php-library.
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.
@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)
- PHP+MongoDB: "Return value must be of type MongoDB\Driver\Server, null returned" HOT 3
- Can we drop `jean85/pretty-package-versions:1.2`? HOT 4
- Decision about `mongo-orchestration` folder and `Makefile` HOT 3
- [Documentation] Syntax highlighting in the method reference is not ideal HOT 1
- A never-ending query after upgrade to MongoDB 6.0.3 HOT 6
- Memory leak on updateOne in the loop HOT 1
- Deprecated: Return type of MongoDB\Model\BSONDocument::bsonSerialize() HOT 2
- The StreamWrapper class is currently unusable without the bucket HOT 4
- Performance issue with PHP 8.2 HOT 2
- Extract mongodb-1.6.2.tgz error HOT 1
- MacOs M1 Cannot connect to Atlas After upgrade driver HOT 7
- This is a test
- $unset not properly work on multiple field? HOT 1
- Docs: missing `]` character in database->aggregate documentation HOT 1
- Question about fieldPaths (feature request?) HOT 1
- Non blocking io HOT 1
- $where is not allowed in this context HOT 2
- TLS connection with mongo cluster failed (while single host works) HOT 2
- getting result from mongodb with toArray() HOT 3
- Getting the error in driver version 1.14 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongo-php-library.