var MongoClient = require('mongodb').MongoClient,
    GridStore = require('mongodb').GridStore,
    Grid = require('mongodb').Grid;
MongoClient.connect("mongodb://localhost/", function(err, db) {
  var gridStore = new GridStore(db, "word_file", 'w');
  gridStore.open(function(err, gridStore) {
    GridStore.exist(db,"word_file", function(err, results) {
      console.log("Czy utworzono plik? " + results);
    });
    gridStore.writeFile('./words.txt', function(err, results) {
      console.log("\nZapisano plik.");
      GridStore.read(db, "word_file", function(err, fileData) {
        console.log("\nPełny odczyt: ");
        console.log(fileData.toString());
        gridStore.seek(100, function(err, gridStore) {
          gridStore.read(50, function(err, data) {
            console.log("\nOdczytano 50 bajtów w pozycji 100: ");
            console.log(data.toString());
            gridStore.close();
            GridStore.unlink(db, "word_file", function(err, results){
              console.log("\nUsunięto plik: " + results._id);
              db.close();
            });
          });
        });
      });
    });
  });
}); 