mongodb

npm install mongodb

Um MongoDB mit NodeJS zu nutzen kann man das NPM Packet mongodb nutzen.

var mongo = require('mongodb'),
    db = new mongo.Db(database, new mongo.Server('host', port, {}), {});

db.open(function() {
    db.collection('collection', function(err, collection) {
        doc = {...}
        collection.insert(doc, function() {
            console.log('insert doc');
        });

        collection.count({...}, function(err, doc) {
            console.log(doc.toString());
        });

        collection.find({...}).toArray(function(err, results) {
            console.log(results);
        });
    });
});

Comments are closed.