Created
May 28, 2010 07:57
-
-
Save kurokikaze/416898 to your computer and use it in GitHub Desktop.
Creating reference in node-mongodb-native
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
var mongo = require('../lib/mongodb'), | |
sys = require('sys'); | |
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('test', new mongo.Server(host, port, {}), {}); | |
db.open(function(err, db) { | |
db.collection('players', function(err, collection) { | |
collection.findOne({"name":'kze'}, function(err, player){ | |
/* db.dereference(player.tank, function(err, tank) { | |
sys.puts('Player ' + player.name + ' tank speed is ' + tank.speed); | |
});*/ | |
collection.insert({'name':'dark', 'identity': new mongo.DBRef('players', player._id)} | |
, function(err) { sys.puts('Reference inserted: ' + JSON.stringify(err))}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment