I am trying to get more than 1000 rows from azure in php.
First of all i am not able to use filter class. which namespace need to be added to use filter class
after that while loop is gng in infinite loop
any help
$tableRestProxy = ServicesBuilder::getInstance()->createTableService($this->connectionString);
$filter = "( PartitionKey eq '$id' )";
$options = new QueryEntitiesOptions();
$options->setFilter(Filter::applyQueryString($filter));
$result = $tableRestProxy->queryEntities('test', $options);
$entities = $result->getEntities();
$nextPartitionKey = $result->getNextPartitionKey();
$nextRowKey = $result->getNextRowKey();
while (!is_null($nextRowKey) && !is_null($nextPartitionKey) ) {
$options = new QueryEntitiesOptions();
$options->setNextPartitionKey($nextPartitionKey);
$options->setNextRowKey($nextRowKey);
$options->setFilter(Filter::applyQueryString($filter));
$result2 = $tableRestProxy->queryEntities("test", $options);
$newentities = $result2->getEntities();
$entities=array_merge($newentities, $entities);
}
link m using is
PHP - Azure Table Storage in with more than 1000 entities
You can leverage setTop() function of MicrosoftAzure\Storage\Table\Models\QueryEntitiesOptions class to select the top X (number) entities of the table.
And according the description at https://github.com/Azure/azure-storage-php/blob/master/src/Table/Models/QueryEntitiesOptions.php#L148, we can find that the filter classes have moved into the namespace MicrosoftAzure\Storage\Table\Models\Filters
If you want to use the filter classes in the new Azure Storage SDK for PHP, you can try to include the package as:
use MicrosoftAzure\Storage\Table\Models\Filters\QueryStringFilter;
Please consider the following code snippet:
use MicrosoftAzure\Storage\Table\Models\QueryEntitiesOptions;
use MicrosoftAzure\Storage\Table\Models\Filters\QueryStringFilter;
$options = new QueryEntitiesOptions();
$filter = new QueryStringFilter("(RowKey eq '".$id."')");
$options->setFilter($filter);
$options->setTop(1000);
Related
I'm a beginner in PHP. My PHP version 7.3 and I cannot use MongoClient class because I have an error. So How can I get the size of the collection MongoDB/Drive class in Php?
$m =new MongoDB\Driver\Manager("mongodb://localhost:27017");
$query = new MongoDB\Driver\Query([]);
$res = $m->executeQuery("Paper.Papers", $query);
print_r(count(iterator_to_array($res)));
My solution is inefficient. Is there a different way?
UPDATE
I found alternative way to get size of collection:
$command = new MongoDB\Driver\Command(["dbstats" => 1]);
$res = $m->executeCommand("Paper", $command);
$stats = current($res->toArray());
Then;
print_r($stats->objects);
Output : 6000
I have a collection with entries like:
"Name":"test",
"Description":"some desc here",
"Teams":[0:"idhash1",1:"idhash2"],
"clientId":"clienthash"
from which I return all items like this:
$filter = array('clientId' => $clientID);
$options = [];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $this->conn->executeQuery('dbname.collectionname', $query);
Now I want to add another filter on team value:
$filter = array('clientId' => $clientID,'Teams'=>'idhash1');
$options = [];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $this->conn->executeQuery('dbname.collectionname', $query);
which obviously doesn't work. How would I get this to work? I am on PHP7.0, MongoDB 4.0 and extension version 1.4.2
This would be helpful
$insert in MongoDB with Php
http://php.net/manual/en/mongocollection.insert.php
What I decided to do was add the teamid's not only in an array but also as separate keys:
"Name":"test",
"Description":"some desc here",
"Teams":[0:"idhash1",1:"idhash2"],
"clientId":"clienthash",
"Team_idhash1":1,
"Team_idhash2":1
Making querying them very easy and it performs a lot better this way filtering on a team.
I'm using the new MongoDB PHP driver. I've been searching how I can get more than 100 records from a query.
I'm using executeCommand to pass the query. I think that in the old driver, the cursor object had a getNext method to get other pages, but It does not have anymore. How can I get the other "pages" from my query?
Simply use MongoDB\Driver\Query and MongoDB\Driver\Manager::executeQuery methods.
Here's a short sample for demonstration:
$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$query = new MongoDB\Driver\Query([], []);
$cursor = $manager->executeQuery('DB.Collection', $query);
$array = $cursor->toArray();
Note that resulting $array contains documents (records) as instances of stdClass Object.
I tried this solution and it returns all the documents in collection.
<?php
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$command = new MongoDB\Driver\Command(array('find' => "testColl"));
$cursor = $manager->executeCommand('testDb', $command);
print_r($cursor->toArray());
?>
How to use Extend to update the field?
Example SQL: UPDATE Empresa SET categorias = 'cat_01' WHERE id_user = 'dlkj83d'
$query = new ParseQuery('Empresa');
$query->equalTo("users", Session::get('user'));
$query->add("categorias", 'cat_01'); <- ERROR
$query->save();
Test
$query = new ParseQuery('Empresa');
$query->equalTo("users", Session::get('user'));
$empresa = new ParseObject($query);
$empresa->add('categorias', array('cat_01'));
$empresa->save();
Does not work.
:(
There is no such ParseQuery::add() function. You are trying to cobble an UPDATE into a SELECT... you have to first find() the resulting ParseObjects and iterate through each one:
$query = new ParseQuery('Empresa');
$query->equalTo('users', Session::get('user'));
$results = $query->find(); // Returns an array of ParseObjects
foreach ($results as $res) {
$res->add('categorias', 'cat_01');
$res->save(); // Make sure you write Exception handling for this in the future
}
There is also a ParseObject::set and setArray function that will achieve the same thing, as add may be getting deprecated.
Perfect.
$query = new ParseQuery('Restaurante');
$query->equalTo("users", Session::get('user'));
$results = $query->first();
$results->add('categorias', array('cat_02'));
$results->save();
I still have some difficulties regarding the method NoSQL. Knowing that the reasoning is different.
Thank you for your attention.
You are part of the development team?
I am trying to query from my table storage by using the Azure SDK for PHP.
My query looks like:
$tableRestProxy = ServicesBuilder::getInstance()->createTableService($this->connectionString);
$filter = "( PartitionKey eq '$id' )";
$options = new QueryEntitiesOptions();
$options->setFilter(Filter::applyQueryString($filter));
$result = $tableRestProxy->queryEntities('test', $options);
$entities = $result->getEntities();
$nextPartitionKey = $result->getNextPartitionKey();
$nextRowKey = $result->getNextRowKey();
while (!is_null($nextRowKey) && !is_null($nextPartitionKey) ) {
$options = new QueryEntitiesOptions();
$options->setNextPartitionKey($nextPartitionKey);
$options->setNextRowKey($nextRowKey);
$options->setFilter(Filter::applyQueryString($filter));
$result2 = $tableRestProxy->queryEntities("test", $options);
$newentities = $result2->getEntities();
$entities=array_merge($newentities, $entities);
}
The issue: When running into the while loop I always get the first 1000 back entities, with the same nextrowkey and nextpartitionkey for each query. Thus it creates an infinit loop.
What am I getting wrong with the continuation of a query?
Any help is appreciated.
#Gaurav: this is true, but occurs only on the second loop (I forgot to add the two lines when posting my code).
I've been trying to find out what's wrong for at least half a day. Finally I got it:
It is due to an older version of the Windows Azure PHP SDK which has a "bug". I stumbled across this "bug" at the bottom of this thread: https://github.com/Azure/azure-sdk-for-php/issues/702
The older version of Windows Azure SDK uses _encodeODataUriValue which seems to be unnecessary.