Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support to save values as integers in mongo collections #300

Closed
wants to merge 2 commits into from

Conversation

hansvn
Copy link

@hansvn hansvn commented Aug 27, 2014

I added support to save values as integers into a mongo collection using the Mongo MongoInt32 and MongoInt64 classes.

When you explicitly want to save a value as an integer to a collection you can do so.
for example if you do:

$object->value = (int) Input::get('value');

The value will be stored as an integer instead of as a String.

@coveralls
Copy link

Coverage Status

Coverage decreased (-39.67%) when pulling 046c68d on hansvn:MongoInt-support into d9f2c51 on jenssegers:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-34.25%) when pulling b73e672 on hansvn:MongoInt-support into d9f2c51 on jenssegers:master.

@hansvn hansvn closed this Aug 28, 2014
@hansvn hansvn reopened this Aug 28, 2014
@coveralls
Copy link

Coverage Status

Coverage decreased (-34.25%) when pulling b73e672 on hansvn:MongoInt-support into d9f2c51 on jenssegers:master.

@hansvn
Copy link
Author

hansvn commented Aug 28, 2014

Ok, it seems this pull request is redundant...
When you just save a value from an input field, just explicitly cast the value to an integer (or double or float or ...) and the value will save just fine as a NumberLong (or just the double value) in the document.

Example:

$age = "23";
$user = new User();
$user->age = (int) $age;  // this will be a NumberLong(23) in the document
$user->height = 1.82;  // this will be stored in the document as {"height" : 1.82}
$user->height = floatval(1.82);  // explicitly set the value as a float
$user->save();

Maybe it's not a bad idea to add this to the docs.

@hansvn hansvn closed this Aug 28, 2014
@hansvn hansvn deleted the MongoInt-support branch August 28, 2014 10:05
@hansvn hansvn restored the MongoInt-support branch August 28, 2014 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants