Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB on Wamp x64 (win x64) = mongo.native_long error

I've a big problem with my development environment.

Context :
My computer : Win 8.1 x64
My WampServer install : x64
My MongoDB install : x64 from http://www.mongodb.org/downloads

I've installed the php extension from http://pecl.php.net/package/mongo.

My problem is that our production server store some 64 bits INT into the database.

When I try, in my development environment, to access to this data, I've got:

MongoCursorException

Cannot natively represent the long 1108547148863410176 on this platform

I found on internet that a parameter of mongoDB called "mongo.native_long = 1" is needed to use 64 bits INT on 64 bits architecture.
But when I try to add this param in my "php.ini" file, the server don't start and give me an error like :

[19-Nov-2014 18:25:52 UTC] PHP Fatal error: PHP Startup: To prevent data corruption, you are not allowed to turn on the mongo.native_long setting on 32-bit platforms in Unknown on line 0

Does my mongoDB extension DLL is build on 32 Bit or I missed something to do ?

like image 603
Eirika Avatar asked Nov 19 '14 18:11

Eirika


2 Answers

For me the only thing that worked was:

ini_set('mongo.long_as_object', 1);

Hope it saves someone's time. It's one of those stupid things that make you wonder: "Why the hell did I become a programmer?"

EDIT: getting proper driver from http://pecl.php.net/package/mongo helped me. I've downloaded latest driver. Check your version using phpinfo() command. E.g. for me, on 64-bit Win7 it's:

PHP Version 5.5.12
PHP Extension Build:    API20121212,TS,VC11

Notice the "TS,VC11" string. It means it's Thread Safe, but your version may not be thread safe (NTS).

So I downloaded 64bit, TS for PHP 5.5. I was dealing with this problem long time and finally, proper driver solved this issue.

like image 53
Rav Avatar answered Sep 19 '22 02:09

Rav


When using a 32 bit apache console(like wampp or xampp) u should add the following to your php.ini file:

mongo.long_as_object= 1

The above line should convert all longs to object, this way the exception won't occur.

Hope this helps all the 32 bit users that have this problem.

like image 22
MrBlueEyes Avatar answered Sep 18 '22 02:09

MrBlueEyes