I've been looking at increasing the amount of MongoDB we use at work, and this includes backing up the data. Due to my own confusion, I had a little issue getting
mongodump writes in a format called Binary JSON, or BSON. I installed BSON.pm with the intention of reading the BSON file and ensuring it works. with small tests, I was able to put objects into BSON, write to file, read from file, and use
But, I find I cannot read the file, because BSON.pm reports it as having an incorrect length.
mongodump
to work, but I have been able to dump from one Mongo database and restore to another.mongodump writes in a format called Binary JSON, or BSON. I installed BSON.pm with the intention of reading the BSON file and ensuring it works. with small tests, I was able to put objects into BSON, write to file, read from file, and use
Data::Dumper
to display the object is what I wanted it to be.But, I find I cannot read the file, because BSON.pm reports it as having an incorrect length.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/djacoby/webserver/perl/bin/perl | |
use feature qw{ say } ; | |
use strict ; | |
use warnings ; | |
use Data::Dumper ; | |
use BSON qw{encode decode} ; | |
my $file = '/home/djacoby/db_backup/mongo/2015-11-06/dave/status.bson' ; | |
if ( open my $fh, '<', $file ) { | |
my $bson = join '', <$fh> ; | |
close $fh ; | |
my $obj = decode( $bson ) ; | |
say Dumper $obj ; | |
} | |
# Incorrect length of the bson string at /home/djacoby/bson_test.pl line 14. |
I fully expect that I'm doing something subtly stupid, but what it could be isn't immediately obvious. the contents of
I suppose I don't need to read the BSON files, but I do like being able to check the contents of a database before restoring.
$bson
should be exactly as written to file, and mongorestore
was happy with it. encode()
and decode()
had worked acceptably, but admittedly on a much smaller dataset than the one I'm working with here, which contains several months of status updates.I suppose I don't need to read the BSON files, but I do like being able to check the contents of a database before restoring.
No comments:
Post a Comment