I'm lost at this point.
Here is what i have:
$criteria = new \EMongoCriteria();
$criteria->userId = new \MongoID($userId);
$criteria->expiresAt = array('>' => new \MongoDate(time()));
Then I'm running this:
$model->count($criteria);
And it always returns 0 when i know that there are documents that meet this criteria.
Any ideas?
UPDATE
findAllByAttributes() with the same criteria works perfectly. But I don't need those documents i need to count them.
When setting criteria field as property it uses simple comparision (field == value). You should set this criteria by calling field, like that:
$criteria->expiresAt('>', new \MongoDate(time()));
NOTE: Passing criteria to findAllByAttributes in wrong, it is not intended to work with EMongoCriteria, but with simple array. If you want to use criteria object pass it to findAll method.
Related
I'm using Elastica and I need to create the filter that will get NULL values along with values that lower than 100.
For now my code looks like this:
$this->filter = $qb->query()->bool();
$this->filter->addShould($qb->query()->range('price', ['lte' => 100]));
It returns data with price lower than 100.
I also need to get data with null values.
So far I tried:
$this->filter->addMustNot($qb->query()->exists('price')); // returns 0 items
$this->filter->addShould($qb->query()->missing('price')); // doesn't work. Gives undefined query "missing" in Facade.php
Could someone help me with this issue? Or how to fix the problem with undefined query "missing" or to create another filter that will fit my needs. Thanks.
Used same range() to make it work how I need.
So it looks like this:
$this->filter->addMustNot($qb->query()->range('price', ['gte' => 100]));
I'm using addMustNot so it filters all values that matches that filter (everything less than 100 will be returned, even if it's null value).
Only one thing I need is to rename all result fields from PHPNAME type into FIELDNAME. I'm running such query:
$members = MemberQuery::create()->filterByOrganizerId($organizerId)
->setFormatter($formatter)
->useTableOneQuery()
->useTableTwoQuery()
->where('TableTwo.Status != ?', TableTwo::STATUS_FAILED)
->endUse()
->endUse()
->groupById()
->paginate($page, $pageSize);
Where $formatter is:
$arrayDataFetcher = new ArrayDataFetcher([]);
$arrayDataFetcher->setIndexType(TableMap::TYPE_FIELDNAME);
$formatter= new ArrayFormatter();
$formatter->setDataFetcher($arrayDataFetcher);
But every array is still having PHPNAME fieldnames. When I do not paginate results and just using find() I can simply use toArray on result and everything is okay, but I can't figure out how to do the same with paginated results
solution is pretty easy. Just use toArray() on your result. Do not trust autocomplete. IDE do not shows that method, but it exists! Trust documentation, check here, and you will see comment that paginated results behave like collection, that's exactly what we need.
Im a bit new to the php side of parse, mainly objective-c and swift but I need to write some code that I can query a column (not the objectID one) to return the results..
The column I'm trying to query is a pointer to another class.
Here is the very basic code I have which returns all the rows in the class and the pointers data with the include key, but I need to filter or get only the row/s that I'm looking for.
$query = new ParseQuery("ClassB");
$query->includeKey("ClassA");
$results = $query->find();
In the php sdk I see an option to use equalTo which has a key and a value to it so I tried the following code.
so I choose the column that was the pointer , and its objectid to hopefully only return those row/s that has that object id.
$query = new ParseQuery("ClassB");
$query->includeKey("ClassA");
$query->equalTo("ColumnNameX", "yjdyaGRWP7");
$results = $query->find();
Nothing was returned and a php error was spit out
'pointer field ColumnNameX needs a pointer value' in /var/www/parse/src/Parse/ParseClient.php:326
So im not 100% sure why I cant filter by a ColumnNameX using its objectID which is a pointer to ClassA..
Did I miss something in the PHP docs..
I mean ideally in mysql to just get that row I want would be
SELECT * FROM ClassB WHERE ColunNameX = yjdyaGRWP7
That would return me the row of data, I can use a Join of course to get some info from ClassA as well.
Any thoughts on what im missing or do I need to first query the Class A to get a pointer, then in the equalTo do something like ("ColumnNamX" , $pointerfromClassA) ?
any one have anyone point out what im missing or have a code example.. I have seen some that use the objectID but I dont have access to that.
Ok I figured out one way to do this, not sure if this is the right way but it returns now what I want..
$query->equalTo("ColunNameX", array("__type" => "Pointer", "className" => "ColunNameX", "objectId" => "yjdyaGRWP7"));
I'm using laravel FindOrNew() to get an entry with two parameters, or create a new one:
$option = \App\Option::findOrNew(['user_id' => $this->id , 'option_name' => $optionName]);
I want to get an option for a user that has the name in $optionName. The problem is that it just checks for the user_id, and does not create a new one when option_name does not exist.. instead it "finds" one which does not match the $optionName value..
Can someone say what I'm doing wrong? How can I achieve this?
TL;DR:
You're using the wrong method. You're looking for the firstOrNew() method, not findOrNew().
Explanation:
The findOrNew() is an extension of the find() method, which works on ids only. It takes two parameters, the first being the id (or array of ids) to find, and the second being the columns to retrieve. It's treating the array you've passed in as an array of ids to find.
The firstOrNew() method takes one parameter: an array of attributes to search for. It will turn the array into a where clause, and then call first() on the query builder. If no results are returned, it returns a new instance with those attributes filled in.
I'm having some difficulties to select the last entry I posted into my Mongo Collection. This is an example of what an object in my collection looks like:
{"category":1,"date:
{"sec":1356521350,"usec":0},"content":"Test Content","_id":
{"$id":"50dadf8639f992c83f000003"}}
Now, I want to sort on the field date and I am trying to do so by using the following functionality (by using the Yii-MongoDB-Suite):
$oCriteria = new EMongoCriteria;
$oCriteria->sort('date', EMongoCriteria::SORT_DESC);
$oOjbect = ObjectModel::model()->find($oCriteria);
Now, instead of returning the object which has the lastest date, it returns me the first object I entered in the collection.
I literally have no clue about what might be going wrong. Any clues?
I believe you need to pass a PHP array to sort(), so what you actually need is:
$oCriteria = new EMongoCriteria;
$oCriteria->sort(array('date', EMongoCriteria::SORT_DESC));
$oOjbect = ObjectModel::model()->find($oCriteria);