From 198283a74c91267798525c406846b84032775870 Mon Sep 17 00:00:00 2001 From: basarat Date: Tue, 27 Aug 2013 22:46:05 +1000 Subject: [PATCH] minor mongoclient class fix + added tests --- mongodb/mongodb-tests.ts | 25 +++++++++++++++++++++++++ mongodb/mongodb.d.ts | 14 +++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 mongodb/mongodb-tests.ts diff --git a/mongodb/mongodb-tests.ts b/mongodb/mongodb-tests.ts new file mode 100644 index 000000000..95333f78c --- /dev/null +++ b/mongodb/mongodb-tests.ts @@ -0,0 +1,25 @@ +/// + +// 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(); + }); + }); +}) \ No newline at end of file diff --git a/mongodb/mongodb.d.ts b/mongodb/mongodb.d.ts index ef9d1cd54..15791a8e5 100644 --- a/mongodb/mongodb.d.ts +++ b/mongodb/mongodb.d.ts @@ -1,9 +1,17 @@ +// Project : https://github.com/mongodb/node-mongodb-native +// Documentation : http://mongodb.github.io/node-mongodb-native/ + + /// declare module "mongodb" { - - export function connect(uri: string, options: any, callback: (err: any, db: Db) => void); - export function connect(uri: string, callback: (err: any, db: Db) => void); + // Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html + export class MongoClient{ + constructor(serverConfig: any, options: any); + + static connect(uri: string, options: any, callback: (err: any, db: Db) => void); + static connect(uri: string, callback: (err: any, db: Db) => void); + } export class Server { constructor (host: string, port: number, opts?: ServerOptions);