Object of class MongoInt64 could not be converted to int

1,035 views
Skip to first unread message

Момчил Божинов

unread,
Jul 3, 2016, 1:21:30 PM7/3/16
to mongodb-user
Hello,

I have read quite a few posts regarding this problem
All of them have been resolved in one way or another.
None help for my issue

I have:
mongodb-win32-x86_64-2008plus-3.2.7
mongodb driver 1.6.14
httpd-2.4.20-win64-VC11
php-5.6.23-Win32-VC11-x64


and I get:
Object of class MongoInt64 could not be converted to int

every time I use the GROUP command:
$result = $this->collection->group(
 array
('sample.yname' => TRUE),
 array
('count' => 0), new \MongoCode('function(doc, prev){ prev.count += 1} '),
 array
('condition' => array('sample.yname' => array('$nin' => array("xxx", "xx", 'x'))))
);

The moment I try to use COUNT I get the NOTICE

my PHP_INT_MAX = 2147483647

Please help
Momchil

Момчил Божинов

unread,
Jul 3, 2016, 1:23:23 PM7/3/16
to mongodb-user
Extra PHP INI settings
mongo.long_as_object= 1
;mongo.native_long=1

Native_long could not be set as PHP would prevent it - memory corruption

Tim Hawkins

unread,
Jul 3, 2016, 4:20:14 PM7/3/16
to mongodb-user

You are using 32bit mongo and php, you need to use 64bit versions.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/24674552-3f42-477d-a57d-554545d076f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Hawkins

unread,
Jul 3, 2016, 4:25:55 PM7/3/16
to mongodb-user

Scratch that, on further investigation those are all 64bit, it was tbe "win32" that was confusing me.

Момчил Божинов

unread,
Jul 4, 2016, 3:30:55 AM7/4/16
to mongodb-user
From what I know v7 is the first true 64 bit version.
I m not there yet though
A lot of refactoring is still required to start using the new mongo glue

Jeremy Mikola

unread,
Jul 5, 2016, 11:42:50 AM7/5/16
to mongod...@googlegroups.com
Can you elaborate on the "memory corruption" here?

If you are using mongo.long_as_object, 64-bit integers in MongoDB will be returned as a MongoInt64 instance and 32-bit integers will be returned as normal PHP integers. Generally, MongoDB will use the smallest integer type possible, so I would not expect a 64-bit integer to be returned unless "count" is sufficiently large (this depends entirely on your aggregation). In any event, you'll need to craft your code to handle either an integer or MongoInt64 result.

Disabling mongo.long_as_object (default behavior) would cause the extension to throw an exception if it encounters a 64-bit integer in BSON.

As you know, PHP 5.x on any Windows architecture is limited to 32-bit integers. The MongoInt64's string representation will be the large integer, which you can either print as-is or pass to an extension like GMP if you need to do arithmetic.

Момчил Божинов

unread,
Jul 6, 2016, 1:52:17 AM7/6/16
to mongodb-user
Hi Jeremy,

I get:
Fatal error: ini_set(): 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

on 
ini_set('mongo.native_long',1); 

my PHP_INT_MAX = 2147483647I guess it is a Windows thing.
Reply all
Reply to author
Forward
0 new messages