Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8110843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:54:04+00:00 2026-06-06T01:54:04+00:00

From the MongoDB manual: By default, all database strings are UTF8. To save images,

  • 0

From the MongoDB manual:

By default, all database strings are UTF8. To save images, binaries,
and other non-UTF8 data, you can pass the string as a reference to the
database.

I’m fetching pages and want store the content for later processing.

  • I can not rely on meta-charset, because many pages has utf8 content but wrongly declaring iso-8859-1 or similar
  • so can’t use Encode (don’t know the originating charset)
  • therefore, I want store the content simply as flow of bytes (binary data) for later processing

Fragment of my code:

sub save {
    my ($self, $ok, $url, $fetchtime, $request ) = @_;

    my $rawhead = $request->headers_as_string;
    my $rawbody = $request->content;

    $self->db->content->insert(
        { "url" => $url, "rhead" => \$rawhead, "rbody" => \$rawbody } ) #using references here
      if $ok;

    $self->db->links->update(
        { "url" => $url },
        {
            '$set' => {
                'status'       => $request->code,
                'valid'        => $ok,
                'last_checked' => time(),
                'fetchtime'    => $fetchtime,
            }
        }
    );
}

But get error:

Wide character in subroutine entry at
/opt/local/lib/perl5/site_perl/5.14.2/darwin-multi-2level/MongoDB/Collection.pm
line 296.

This is the only place where I storing data.

The question: The only way store binary data in MondoDB is encode them e.g. with base64?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:54:05+00:00Added an answer on June 6, 2026 at 1:54 am

    It looks like another sad story about _utf8_ flag…

    I may be wrong, but it seems that headers_as_string and content methods of HTTP::Message return their strings as a sequence of characters. But MongoDB driver expects the strings explicitly passed to it as ‘binaries’ to be a sequence of octets – hence the warning drama.

    A rather ugly fix is to take down the utf8 flag on $rawhead and $rawbody in your code (I wonder shouldn’t it be really done by MongoDB driver itself?), by something like this…

    _utf8_off $rawhead; 
    _utf8_off $rawbody; # ugh
    

    The alternative is to use encode('utf8', $rawhead) – but then you should use decode when extracting values from DB, and I doubt it’s not uglier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web page where users can see data from MongoDB on a
I get data from mongodb in php and display fields in table. Can I
Pulling some data from MongoDB and inserting it into a MySQL database, using Python
I wanted to extract data from mongodb and pass it to the view. Everything
How can you drop a numeric collection from MongoDB? PRIMARY> db.123456789011.remove({}); Tue Mar 20
I am using mongoose/nodejs to get data as json from mongodb. For using mongoose
I know that it is possible read and write data from mongodb via hadoop.
I'm looking to retrieve some data from MongoDB but I'm unsure of how to
I've written a script to pull data from MongoDB and output seemingly valid XML
with MongoDB (and I assume other NoSQL database APIs worth their salt) the ways

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.