amark / mongous

Simple MongoDB driver for Node.js with jQuery like syntax.
MIT License
246 stars 30 forks source link

Is there a complete runnable example code? #27

Closed mocheng closed 11 years ago

mocheng commented 11 years ago

The sample code doesn't tell how to specify hostname and port number. It would be much helpful to have a complete example code.

amark commented 11 years ago

@mocheng Sorry for the delayed response -- I never got an email about this!

The documentation is friendly: db().open(host,port)

If you are a newb to things, here is a fully functional example: (please make sure MongoDB is already running) (please make sure you have appropriately installed mongous)

var $ = require("mongous").Mongous, 
db = 'theory.state', 
val = {way:'index'};
$().open('localhost', 27017); 

$(db).save(val);
$(db).find({},function(r){
    console.log("saved");
    console.log(r);
    $(db).remove(val);
    $(db).find({},function(r){
        console.log("remove");
        console.log(r);
    });
});

I hope this helps!