-
Notifications
You must be signed in to change notification settings - Fork 52
errors to query documents with fields consisting of numberic characters #79
Comments
A fix for this would be prepend your numeric fields with something like field_{numeric index here}. Since your dealing in document objects, your attributes should have some sort of meaning other than purely numeric indexes. |
Mongodb allows to use such fields. Sometimes it's convinient to use such fields. |
Right now, I fixed it changing |
I guess it depends on your development situation. If your a lone programmer that will never have anyone ever look at your code and you will never forget why you have a 1 there, then yes your right, it can be convenient to have your object attributes be numeric indexes. I cant really think of any other reason why you would want to put data into a a DB without any contextual representation of why it is there or what it is. |
I pushed your fix into my branch for general consumption |
One of situation when it's useful this one: converting Entity Attribute Values model in rdbms, leaving descriptions of fields in rdbs, something like fields_id field_name type. And storing all values in mongodb collection, to prevent all difficulties with gathering all atrributes of objects. In this case attributes could be stores like {field_id: values} |
5 апреля 2012 г. 18:10 пользователь gwagner
|
I guess it is a 6 of one, half a dozen of the other type of situation. Since your doing a numeric link between field name in mongo and RDBMS, you could also do a field name link between RDBMS (again depending on your RDBMS setup if your have a proper short name such a field_name_abcde) which would take care of the bug in the PHP Mongo Driver, and take care of giving you a textual representation in your data set (for administration and bug tracking later). Either way, thanks for the code that fixed your problem! Hopefully it can be useful to the community as a whole! |
Fields_id is autoincremented integer field. |
Querying of documents with fields consisting of numberic characters fails.
For example, if I have a fields that consists only of number something like "1" : 'value' and I try to use:
return MyDocument::all($condition, $fields);
I get an error:
An error occurred
Application error
Exception information:
Message: field names must be strings
Stack trace:
#0 C:\library\Shanty\Mongo\Collection.php(376):
MongoCollection->find(Array, Array)
#1 C:\git_reps\mailable\application\models\Subscriber1.php(191):
Shanty_Mongo_Collection::all(Array, Array)
#2 C:\git_reps\mailable\application\models\Subscriber1.php(203):
Model_Subscriber1::getCursor(Array, Array, Array)
#3 C:\git_reps\mailable\application\controllers\ListsController.php(639):
Model_Subscriber1::getPaginator(Array, Array, Array)
#4 C:\library\Zend\Controller\Action.php(513): ListsController->view1Action()
#5 C:\library\Zend\Controller\Dispatcher\Standard.php(295):
Zend_Controller_Action->dispatch('view1Action')
#6 C:\library\Zend\Controller\Front.php(954):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http))
#7 C:\library\Zend\Application\Bootstrap\Bootstrap.php(97):
Zend_Controller_Front->dispatch()
#8 C:\library\Zend\Application.php(366):
Zend_Application_Bootstrap_Bootstrap->run()
#9 C:\git_reps\mailable\public\index.php(25): Zend_Application->run()
#10 {main}
Request Parameters:
array (
'controller' => 'lists',
'action' => 'view1',
'module' => 'default',
'id' => '52',
It throws error on 376 line in Collection.php:
$cursor = static::getMongoCollection(false)->find($query, $fields);
It looks like if to replace it with:
$cursor = static::getMongoCollection(false)->find($query)->fields($fields);
it works with fields consisting only of number too, maybe corrects the problem.
Maybe it's connected with some bug in php driver:
https://jira.mongodb.org/browse/PHP-338.
Please let me know about your ideas. Maybe to fix it like this?
The text was updated successfully, but these errors were encountered: