Perl and boolean values

83 views
Skip to first unread message

Kevin

unread,
Sep 28, 2009, 11:46:09 AM9/28/09
to mongodb-user
Hi,

I have stored into mongodb a lot of records with boolean fields like:
{"_id" : "675000197" , "270" : true , "340" : true}

And now I am trying to query from perl all records having "270" set to
true, but it seems that the boolean type is not managed by the perl
driver. Or I don't know how to pass it as the boolean type don't
really exist in perl. I have tried like this without any success:

my $cursor = $collection->query({ 270 => JSON::true }, { limit =>
10 });
my $cursor = $collection->query({ 270 => boolean::true }, { limit =>
10 });
my $cursor = $collection->query({ 270 => true }, { limit => 10 });
my $cursor = $collection->query({ 270 => "true" }, { limit => 10 });
my $cursor = $collection->query({ 270 => 0X1 }, { limit => 10 });
my $cursor = $collection->query({ 270 => 1 }, { limit => 10 });
my $cursor = $collection->query({ 270 }, { limit => 10 });

Does anybody have an idea on how to query regarding a boolean value
from perl?

Thank you in advance for your help :)

Kristina Chodorow

unread,
Sep 28, 2009, 11:51:27 AM9/28/09
to mongod...@googlegroups.com
Unfortunately, the Perl driver can't query for booleans, as Perl doesn't have a boolean type.   So, you need to save these as 0 and 1.

If anyone has any suggestions on how booleans should be handled, please share!

Kristina Chodorow

unread,
Sep 28, 2009, 12:01:29 PM9/28/09
to mongod...@googlegroups.com
Hmm, it could use boolean::true/boolean::false, would that work for people?

Kristina Chodorow

unread,
Sep 28, 2009, 3:18:50 PM9/28/09
to mongod...@googlegroups.com
Okay, if you download the latest code from Github (github.com/mongodb/mongo-perl-driver), you can use the boolean package's true and false to save/query for booleans.

It will be in the next CPAN release if you'd like to wait, which will be in a week or two.

Kevin

unread,
Sep 29, 2009, 2:37:26 AM9/29/09
to mongodb-user
Thank you a lot for your amazingly fast modification, I will try it
now.

On 28 sep, 21:18, Kristina Chodorow <krist...@10gen.com> wrote:
> Okay, if you download the latest code from Github (
> github.com/mongodb/mongo-perl-driver), you can use the boolean package's
> true and false to save/query for booleans.
>
> It will be in the next CPAN release if you'd like to wait, which will be in
> a week or two.
>
> On Mon, Sep 28, 2009 at 12:01 PM, Kristina Chodorow <krist...@10gen.com>wrote:
>
> > Hmm, it could use boolean::true/boolean::false, would that work for people?
>
> > On Mon, Sep 28, 2009 at 11:51 AM, Kristina Chodorow <krist...@10gen.com>wrote:
>
> >> Unfortunately, the Perl driver can't query for booleans, as Perl doesn't
> >> have a boolean type.   So, you need to save these as 0 and 1.
>
> >> If anyone has any suggestions on how booleans should be handled, please
> >> share!
>

Kevin

unread,
Sep 29, 2009, 3:04:14 AM9/29/09
to mongodb-user
It works like a charm. :)

By the way every time I try to compile the perl module I get an error
during the make:
perl_mongo.c:519: error: conflicting types for
'perl_mongo_serialize_long'
perl_mongo.h:92: error: previous declaration of
'perl_mongo_serialize_long' was here
perl_mongo.c:519: error: conflicting types for
'perl_mongo_serialize_long'
perl_mongo.h:92: error: previous declaration of
'perl_mongo_serialize_long' was here

So I had to replace into perl_mongo.h "long long" by "int64_t", and
after that it compiles. (probably it comes from my environment, it is
a crappy test machine...)

Kristina Chodorow

unread,
Sep 29, 2009, 11:41:29 AM9/29/09
to mongod...@googlegroups.com
Great, glad it worked! Thanks for letting me know about the int64_t
thing, I'll fix that in master. What system are you using?
Reply all
Reply to author
Forward
0 new messages