Created
June 19, 2010 22:27
-
-
Save nw/445353 to your computer and use it in GitHub Desktop.
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
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}; |
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
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