Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.
Showing posts with label nosql. Show all posts
Showing posts with label nosql. Show all posts

2015/11/06

Trying to Read MongoDB dump files using BSON

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 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.


I fully expect that I'm doing something subtly stupid, but what it could be isn't immediately obvious. the contents of $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.

2015/05/12

Having an issue with MongoDB and Perl

I've learned to love SQL. At first I had lots of functions that did SELECT * FROM table, then I would put everything together at the last moment, with big slow programs. Slowly but surely, I found myself trusting my tools more and more, writing more and more complex SQL queries to give me exactly what I needed, in as close to the right form as I could.

Now that I have some level of expertise with SQL, we have it as a core of our infrastructure at work, so any experimenting with NoSQL databases. It's mostly for my toy bits and administrivia, not really holding any real data, but I am keeping my current FitBit step count in it.

I am currently finding that I can find_one() all I want, but I can't find(). I am sure I used to. I'm also sure that I'm doing something stupid, not the MongoDB Perl module, but I can't tell what I'm doing wrong.

Help?


2015/05/04

Putting Current Temperature into my Bash Prompt

my life as drawn by phdcomics.com
I work in a sub-basement. I've been lead to understand that this is desirable for us because the lab equipment is on the solid cement of the foundation, so that we don't have to worry about footsteps shaking it, but I honestly don't know.

The problem at least for me, is that it I'm well-isolated from the outside world, so that it could just as easily 9° or 90° outside, and I wouldn't know. I've felt apprehension to wander upstairs, only to find that, once I got there, it wasn't all that bad.

With a previous printer, I would write the current conditions to the front-panel LCD, because Perl, but we've moved from HP to Xerox, and I no longer have that ability. I now have it tell the time and temp at the top and bottom of the hour, to keep from being so deep in the zone that I think it's lunchtime when it's really quittin' time. I also had code to generate notify balloons, but a recent switch from Ubuntu to Debian made that unusable.

I've been playing with NoSQL databases and have found that I spend most of my time with MongoDB, but once I started thinking about the weather problem — I need it to be available to any of my n terminals, I don't need structure — I decided that Redis was the way to go.

Each NoSQL database works in a different way. MongoDB works as a Document Store, holding a piece of structured data until you call it back. I have code to record daily status updates and send it to bosses where each day holds an array full of objects holding a timestamp and status report, and at 6pm, if the day's array holds data, it formats that data and sends the mail. This is more structure than I really need in this context.

What I really need is essentially a hash table that I can access from many different programs. If it falls down, that's fine; I don't need to remember what the temperature was at 4am, I just need to know what it is now, or within the last 10 minutes. Redis works like that, and (unless you have it commit to disc), it's only in memory, so fast. (I think; I've only played with Redis, not put production data into it.) I think this feature would be good in, for example, Raspberry Pi uses, where excessive access could prematurely kill your SD card.

Anyway, here's my code to store the temperature, to pull it back out, and a replacement $PS1 to show you how to add it to your prompt. It backends to forecast.io, my most recent go-to for weather information. The API is very useful and easy to use. (I don't put "Powered by Forecast" in my prompt but I do put it in the program that uses notify-osd and Pushover.) Use it in good weather.