從MongoDB手冊:的Perl和MongoDB的二進制數據
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.
我獲取網頁,並想要保存以便以後處理的內容。
- 我不能依賴於元字符集,因爲很多網頁有utf8的內容,但錯誤地宣稱ISO-8859-1或類似
- 所以不能用
Encode
(不知道原始字符集) - 因此,我想保存以便以後處理
片段我的代碼的內容簡單地as flow of bytes
(二進制數據):
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,
}
}
);
}
,但得到的錯誤:
Wide character in subroutine entry at /opt/local/lib/perl5/site_perl/5.14.2/darwin-multi-2level/MongoDB/Collection.pm line 296.
這是我存儲數據的地方。
問題:在MondoDB中存儲二進制數據的唯一方法是對它們進行編碼,例如用base64?
如果您將'$ rawhead'和'$ rawbody'設置爲手冊中給出的示例(即「\ xFF \ xFE \ xFF」'),它會給出相同的警告嗎? – raina77ow