&lt or &gt with string

376 views
Skip to first unread message

KingCanadian

unread,
May 2, 2012, 4:33:03 AM5/2/12
to mongodb-user
Hello,

i have a very large number in mongodb saved as a string because
my php is 32bit and int is not big enough.

I tried:
array (
'scan_tsp' => array($lt => 20120502101406)
)

But it does not work - message: For your security, we stoped data
parsing at '(T_VARIABLE) $lt'.



Is there any way to do a &lt or &gt with this string?

Regards,
Juergen

Derick Rethans

unread,
May 2, 2012, 5:01:54 AM5/2/12
to mongodb-user
On Wed, 2 May 2012, KingCanadian wrote:

> i have a very large number in mongodb saved as a string because my php
> is 32bit and int is not big enough.

I would strongly suggest to use a 64 bit build of PHP if you'd like
this. Also please read
http://derickrethans.nl/64bit-ints-in-mongodb.html

> I tried:
> array (
> 'scan_tsp' => array($lt => 20120502101406)
> )

You need to use single quotes around operators.

array (
'scan_tsp' => array('$lt' => 20120502101406)
)

> But it does not work - message: For your security, we stoped data
> parsing at '(T_VARIABLE) $lt'.

That is interesting, I've never seen that error before... it's AFAIK not
part of a normal PHP installation.

> Is there any way to do a &lt or &gt with this string?

Yes, '$lt' and '$gt' will work with strings, but you need to make sure
to compare against a string then, and your example still shows you're
passing in an integer. Your code should be:

array (
'scan_tsp' => array('$lt' => '20120502101406')
)

cheers,
Derick

--
http://mongodb.org | http://derickrethans.nl
twitter: @derickr and @mongodb

Sam Millman

unread,
May 2, 2012, 5:21:55 AM5/2/12
to mongod...@googlegroups.com
There is a specific INT object in mongo called:

http://www.php.net/manual/en/class.mongoint64.php

Which will let you store 64bit numbers.


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Nat

unread,
May 2, 2012, 5:29:07 AM5/2/12
to mongod...@googlegroups.com
Your error message actually is something to do with $lt, you should use '$lt' (in single quotes) instead. For datetime, if you store it as string, you can pass string to compare instead of using number.
From: Sam Millman <sam.m...@gmail.com>
Date: Wed, 2 May 2012 10:21:55 +0100
Subject: Re: [mongodb-user] &lt or &gt with string

KingCanadian

unread,
May 2, 2012, 6:08:38 AM5/2/12
to mongodb-user
Thank you very much Derick!

With single-quotes it works as expected.

Problem is solved.
Reply all
Reply to author
Forward
0 new messages