Skip to content

Instantly share code, notes, and snippets.

@nw
Created June 19, 2010 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nw/445353 to your computer and use it in GitHub Desktop.
Save nw/445353 to your computer and use it in GitHub Desktop.
result = {'array':[1,2,3],
'string':'hello',
'hash':{'a':1, 'b':2},
'date':new Date(), // Stores only milisecond resolution
'int':42,
'float':33.3333,
'regexp':/foobar/i,
'boolean':true,
'null':null};
GLOBAL.DEBUG = true;
sys = require("sys");
test = require("mjsunit");
fs = require('fs');
Script = process.binding('evals').Script;
sandbox = {};
file = fs.readFileSync('sample.js');
Script.runInNewContext(file, sandbox);
sys.puts(sys.inspect(sandbox));
var mongo = require('../lib/mongodb');
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT'] : mongo.Connection.DEFAULT_PORT;
sys.puts("Connecting to " + host + ":" + port);
var db = new mongo.Db('node-mongo-examples', new mongo.Server(host, port, {}), {});
db.open(function(err, db) {
db.collection('test', function(err, collection) {
// Remove all existing documents in collection
collection.remove(function(err, collection) {
// Insert record with all the available types of values
collection.insert(sandbox.result, function(err, doc) {
// Locate the first document
collection.findOne(function(err, document) {
sys.puts(sys.inspect(document));
collection.remove(function(err, collection) {
db.close();
});
})
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment