MongoID Saving Problem

8 views
Skip to first unread message

BlackMage

unread,
Jan 27, 2012, 10:57:16 PM1/27/12
to MongoLantern
I'm saving MongoID to an Unindexed field but it always comes back as
the number 4.


$docObj -> setField(MongoLanternField::Keyword('tags', $tags)) ;
$docObj -> setField(MongoLanternField::Text('tags', $tags));
$docObj -> setField(MongoLanternField::UnIndexed('_id', $this ->
_id));
$docObj -> setField(MongoLanternField::UnIndexed('image_id', (string)
$this -> image_id));
$docObj -> setField(MongoLanternField::UnIndexed('preview_id',
(string) $this -> image_locations -> preview -> preview_id));
$docObj -> setField(MongoLanternField::UnIndexed('thumbnail_id',
(string) $this->image_locations -> thumbnail -> thumbnail_id));

MongoDB Data

"_id": 4,
"image_id": 4,
"preview_id": 4,
"thumbnail_id": 4

BlackMage

unread,
Jan 27, 2012, 11:17:30 PM1/27/12
to MongoLantern
The problem is occuring in a similar spot

else if(true === MongoLanternValidate::isFloat($content)) {
echo 'Here id'.$content;
return (float) $content;
}

An easy fix might be

if(!MongoLanternValidate::isMongoID() && true ===
MongoLanternValidate::isFloat($content)) {
echo 'Here id'.$content;
return (float) $content;
}

Which would be:
if ( preg_match('{[0-9a-f]{24}}', $id)) {
$validation = true;
}

Or fix the isFloat method.

BlackMage

unread,
Jan 27, 2012, 11:41:37 PM1/27/12
to MongoLantern
Also, from a coding stand point, in PHP float and doubles are the same
thing, and the C level, they are both stored as doubles. Another
solution might be:

$validation = false;

if (is_numeric($double) === TRUE) {
if ((double)$double == $double) {
$validation = true;
}
}

return $validation;

Sougata Pal.

unread,
Jan 27, 2012, 11:46:51 PM1/27/12
to mongol...@googlegroups.com

YES.

CAN YOU SUBMIT THE FUNCTIONS WITH FILENAME. SO I CAN UPDATE IT TO NEXT RELEASE .

Thanks
Sougata Pal

- Sent via Google Android

ProdigyView

unread,
Jan 27, 2012, 11:53:17 PM1/27/12
to mongol...@googlegroups.com
Sure, here is the isFloat validation fixed.
Validate.php

BlackMage

unread,
Jan 27, 2012, 11:54:37 PM1/27/12
to MongoLantern
And it didn't attach. This will save the IDS.

class MongoLanternValidate {
public static function isFloat($content) {
$validation = false;

if (is_numeric($content) === TRUE) {
if ((double)$content == $content) {
$validation = true;
}
}

return $validation;
}

On Jan 27, 11:53 pm, ProdigyView <cont...@prodigyview.com> wrote:
> Sure, here is the isFloat validation fixed.

Sougata Pal.

unread,
Jan 27, 2012, 11:55:38 PM1/27/12
to mongol...@googlegroups.com

Ok.  Thanks for fixings.

Let me know your name and email to be added to contributors list.

Thanks
Sougata Pal

- Sent via Google Android

On Jan 28, 2012 10:23 AM, "ProdigyView" <con...@prodigyview.com> wrote:
Sure, here is the isFloat validation fixed.

On Jan 27, 2012, at 11:46 PM, Sougata Pal. wrote:

ProdigyView

unread,
Jan 28, 2012, 12:04:00 AM1/28/12
to mongol...@googlegroups.com
Devin Dixon

or 

ProdigyView

Either or.
Reply all
Reply to author
Forward
0 new messages