DefinitelyTyped/mongodb/mongodb-tests.ts
2015-02-10 15:55:31 +02:00

31 lines
904 B
TypeScript

///<reference path="mongodb.d.ts"/>
// Test source : https://github.com/mongodb/node-mongodb-native
import mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;
var format = require('util').format;
MongoClient.connect('mongodb://127.0.0.1:27017/test', function (err, db) {
if (err) throw err;
var collection = db.collection('test_insert');
collection.insert({ a: 2 }, function (err, docs) {
collection.count(function (err, count) {
console.log(format("count = %s", count));
});
// Locate all the entries using find
collection.find().toArray(function (err, results) {
console.dir(results);
// Let's close the db
db.close();
});
// Get some statistics
collection.stats(function (err, stats) {
console.log(stats.count + " documents");
});
});
})