I am new to both Node.js and MongoDB, but I intend to create a very basic real time geolocation based web app. Here is my attempt at figuring out how Node and MongoDB interact:
var mongo = require('mongodb');
var db = new mongo.Db('test', new mongo.Server('localhost',22892, {}), {});
db.open(function(){});
db.collection('docs', function(err,collection){
doc = {"foo":"bar"};
collection.insert(doc, function(){});
});
I can see that this is connecting:
Thu Apr 14 15:24:12 [initandlisten] connection accepted from 127.0.0.1:46968 #26
Thu Apr 14 15:24:12 [conn26] building new index on { _id: 1 } for test.docs
Thu Apr 14 15:24:12 [conn26] done for 0 records 0secs
But it's not inserting any documents into the database. Can anyone tell me what I am doing wrong?
Thanks