diff --git a/acl/acl.d.ts b/acl/acl.d.ts index 57e85d9d5..66fee09d1 100644 --- a/acl/acl.d.ts +++ b/acl/acl.d.ts @@ -7,7 +7,7 @@ /// /// -/// +/// declare module "acl" { import http = require('http'); diff --git a/mongodb/mongodb-1.4.9-tests.ts b/mongodb/mongodb-1.4.9-tests.ts new file mode 100644 index 000000000..3f3efbb55 --- /dev/null +++ b/mongodb/mongodb-1.4.9-tests.ts @@ -0,0 +1,30 @@ +/// + +// 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"); + }); + }); +}) diff --git a/mongodb/mongodb-1.4.9.d.ts b/mongodb/mongodb-1.4.9.d.ts new file mode 100644 index 000000000..2458dbdf2 --- /dev/null +++ b/mongodb/mongodb-1.4.9.d.ts @@ -0,0 +1,543 @@ +// Type definitions for MongoDB +// Project: https://github.com/mongodb/node-mongodb-native +// Definitions by: Boris Yankov +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +// Documentation : http://mongodb.github.io/node-mongodb-native/ + +/// + +declare module "mongodb" { + + // 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, callback?: (err: Error, db: Db) => void): void; + static connect(uri: string, options: any, callback?: (err: Error, db: Db) => void): void; + } + + // Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/server.html + export class Server { + constructor (host: string, port: number, opts?: ServerOptions); + + public connect(): any; + } + + // Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/db.html + export class Db { + constructor (databaseName: string, serverConfig: Server, dbOptions?: DbCreateOptions); + + public db(dbName: string): Db; + + public open(callback?: (err : Error, db : Db) => void ): void; + public close(forceClose?: boolean, callback?: (err: Error, result: any) => void ): void; + public admin(callback?: (err: Error, result: any) => void ): any; + public collectionsInfo(collectionName: string, callback?: (err: Error, result: any) => void ): void; + public collectionNames(collectionName: string, options: any, callback?: (err: Error, result: any) => void ): void; + + public collection(collectionName: string): Collection; + public collection(collectionName: string, callback?: (err: Error, collection: Collection) => void ): Collection; + public collection(collectionName: string, options: MongoCollectionOptions, callback?: (err: Error, collection: Collection) => void ): Collection; + + public collections(callback?: (err: Error, collections: Collection[]) => void ): void; + public eval(code: any, parameters: any[], options?: any, callback?: (err: Error, result: any) => void ): void; + //public dereference(dbRef: DbRef, callback?: (err: Error, result: any) => void): void; + + public logout(callback?: (err: Error, result: any) => void ): void; + public logout(options: any, callback?: (err: Error, result: any) => void ): void; + + public authenticate(userName: string, password: string, callback?: (err: Error, result: any) => void ): void; + public authenticate(userName: string, password: string, options: any, callback?: (err: Error, result: any) => void ): void; + + public addUser(username: string, password: string, callback?: (err: Error, result: any) => void ): void; + public addUser(username: string, password: string, options: any, callback?: (err: Error, result: any) => void ): void; + + public removeUser(username: string, callback?: (err: Error, result: any) => void ): void; + public removeUser(username: string, options: any, callback?: (err: Error, result: any) => void ): void; + + public createCollection(collectionName: string, callback?: (err: Error, result: Collection) => void ): void; + public createCollection(collectionName: string, options: CollectionCreateOptions, callback?: (err: Error, result: any) => void ): void; + + public command(selector: Object, callback?: (err: Error, result: any) => void ): void; + public command(selector: Object, options: any, callback?: (err: Error, result: any) => void ): void; + + public dropCollection(collectionName: string, callback?: (err: Error, result: any) => void ): void; + public renameCollection(fromCollection: string, toCollection: string, callback?: (err: Error, result: any) => void ): void; + + public lastError(options: Object, connectionOptions: any, callback?: (err: Error, result: any) => void ): void; + public previousError(options: Object, callback?: (err: Error, result: any) => void ): void; + + // error = lastError + // lastStatus = lastError + + public executeDbCommand(command_hash: any, callback?: (err: Error, result: any) => void ): void; + public executeDbCommand(command_hash: any, options: any, callback?: (err: Error, result: any) => void ): void; + + public executeDbAdminCommand(command_hash: any, callback?: (err: Error, result: any) => void ): void; + public executeDbAdminCommand(command_hash: any, options: any, callback?: (err: Error, result: any) => void ): void; + + public resetErrorHistory(callback?: (err: Error, result: any) => void ): void; + public resetErrorHistory(options: any, callback?: (err: Error, result: any) => void ): void; + + public createIndex(collectionName: any, fieldOrSpec: any, options: IndexOptions, callback?: Function): void; + public ensureIndex(collectionName: any, fieldOrSpec: any, options: IndexOptions, callback?: Function): void; + + public cursorInfo(options: any, callback?: Function): void; + + public dropIndex(collectionName: string, indexName: string, callback?: Function): void; + public reIndex(collectionName: string, callback?: Function): void; + public indexInformation(collectionName: string, options: any, callback?: Function): void; + public dropDatabase(callback?: (err: Error, result: any) => void ): void; + + public stats(options: any, callback?: Function): void; + public _registerHandler(db_command: any, raw: any, connection: any, exhaust: any, callback?: Function): void; + public _reRegisterHandler(newId: any, object: any, callback?: Function): void; + public _callHandler(id: any, document: any, err: any): any; + public _hasHandler(id: any): any; + public _removeHandler(id: any): any; + public _findHandler(id: any): { id: string; callback?: Function; }; + public __executeQueryCommand(self: any, db_command: any, options: any, callback?: any): void; + + public DEFAULT_URL: string; + + public connect(url: string, options: { uri_decode_auth?: boolean; }, callback?: (err: Error, result: any) => void ): void; + + public addListener(event: string, handler:(param: any) => any): any; + } + + // Class documentation : http://mongodb.github.io/node-mongodb-native/api-bson-generated/objectid.html + // Last update: doc. version 1.3.13 (28.08.2013) + export class ObjectID { + constructor (s?: string); + + // Returns the ObjectID id as a 24 byte hex string representation + public toHexString() : string; + + // Compares the equality of this ObjectID with otherID. + public equals(otherID: ObjectID) : boolean; + + // Returns the generation date (accurate up to the second) that this ID was generated. + public getTimestamp(): Date; + + // Creates an ObjectID from a second based number, with the rest of the ObjectID zeroed out. Used for comparisons or sorting the ObjectID. + // time – an integer number representing a number of seconds. + public static createFromTime(time: number): ObjectID; + + // Creates an ObjectID from a hex string representation of an ObjectID. + // hexString – create a ObjectID from a passed in 24 byte hexstring. + public static createFromHexString(hexString: string): ObjectID; + + // Checks if a value is a valid bson ObjectId + // id - Value to be checked + public static isValid(id: string): Boolean; + + // Generate a 12 byte id string used in ObjectID's + // time - optional parameter allowing to pass in a second based timestamp + public generate(time?: number): string; + } + + // Class documentation : http://mongodb.github.io/node-mongodb-native/api-bson-generated/binary.html + export class Binary { + constructor (buffer: Buffer, subType?: number); + + // Updates this binary with byte_value + put(byte_value: any): void; + + // Writes a buffer or string to the binary + write(buffer: any, offset: number): void; + + // Reads length bytes starting at position. + read(position: number, length: number): Buffer; + + // Returns the value of this binary as a string. + value(): string; + + // The length of the binary. + length(): number; + } + + export interface SocketOptions { + //= set seconds before connection times out default:0 + timeout?: number; + //= Disables the Nagle algorithm default:true + noDelay?: boolean; + //= Set if keepAlive is used default:0 , which means no keepAlive, set higher than 0 for keepAlive + keepAlive?: number; + //= ‘ascii’|’utf8’|’base64’ default:null + encoding?: string; + } + + export interface ServerOptions { + // - to reconnect automatically, default:false + auto_reconnect?: boolean; + // - specify the number of connections in the pool default:1 + poolSize?: number; + // - a collection of pr socket settings + socketOptions?: any; + } + + export interface PKFactory { + counter: number; + createPk: () => number; + } + + // See : http://mongodb.github.io/node-mongodb-native/api-generated/db.html + // Current definition by documentation version 1.3.13 (28.08.2013) + export interface DbCreateOptions { + // the write concern for the operation where < 1 is no acknowlegement of write and w >= 1, w = ‘majority’ or tag acknowledges the write. + w?: any; + + // set the timeout for waiting for write concern to finish (combines with w option). + wtimeout?: number; + + // write waits for fsync before returning. default:false. + fsync?: boolean; + + // write waits for journal sync before returning. default:false. + journal?: boolean; + + // the prefered read preference. use 'ReadPreference' class. + readPreference?: string; + + // use c++ bson parser. default:false. + native_parser?: boolean; + + // force server to create _id fields instead of client. default:false. + forceServerObjectId?: boolean; + + // custom primary key factory to generate _id values (see Custom primary keys). + pkFactory?: PKFactory; + + // serialize functions. default:false. + serializeFunctions?: boolean; + + // peform operations using raw bson buffers. default:false. + raw?: boolean; + + // record query statistics during execution. default:false. + recordQueryStats?: boolean; + + // number of miliseconds between retries. default:5000. + retryMiliSeconds?: number; + + // number of retries off connection. default:5. + numberOfRetries?: number; + + // an object representing a logger that you want to use, needs to support functions debug, log, error. default:null. + logger?: Object + + // force setting of SlaveOk flag on queries (only use when explicitly connecting to a secondary server). default:null. + slaveOk?: number; + + // when deserializing a Long will fit it into a Number if it’s smaller than 53 bits. default:true. + promoteLongs?: boolean; + } + + export class ReadPreference { + public static PRIMARY: string; + public static PRIMARY_PREFERRED: string; + public static SECONDARY: string; + public static SECONDARY_PREFERRED: string; + public static NEAREST: string; + } + + // See : http://mongodb.github.io/node-mongodb-native/api-generated/collection.html + // Current definition by documentation version 1.3.13 (28.08.2013) + export interface CollectionCreateOptions { + // the prefered read preference. use 'ReadPreference' class. + readPreference?: string; + + // Allow reads from secondaries. default:false. + slaveOk?: boolean; + + // serialize functions on the document. default:false. + serializeFunctions?: boolean; + + // perform all operations using raw bson objects. default:false. + raw?: boolean; + + // object overriding the basic ObjectID primary key generation. + pkFactory?: PKFactory; + } + + // Documentation: http://docs.mongodb.org/manual/reference/command/collStats/ + export interface CollStats { + // Namespace. + ns: string; + + // Number of documents. + count: number; + + // Collection size in bytes. + size: number; + + // Average object size in bytes. + avgObjSize: number; + + // (Pre)allocated space for the collection in bytes. + storageSize: number; + + // Number of extents (contiguously allocated chunks of datafile space). + numExtents: number; + + // Number of indexes. + nindexes: number; + + // Size of the most recently created extent in bytes. + lastExtentSize: number; + + // Padding can speed up updates if documents grow. + paddingFactor: number; + flags: number; + + // Total index size in bytes. + totalIndexSize: number; + + // Size of specific indexes in bytes. + indexSizes: { + _id_: number; + username: number; + }; + } + + // Documentation : http://mongodb.github.io/node-mongodb-native/api-generated/collection.html + export interface Collection { + new (db: Db, collectionName: string, pkFactory?: Object, options?: CollectionCreateOptions): Collection; // is this right? + /** + * @deprecated use insertOne or insertMany + * Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#insert + */ + insert(query: any, callback?: (err: Error, result: any) => void): void; + insert(query: any, options: { safe?: any; continueOnError?: boolean; keepGoing?: boolean; serializeFunctions?: boolean; }, callback?: (err: Error, result: any) => void): void; + + // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#insertOne + insertOne(doc:any, callback?: (err: Error, result: any) => void) :void; + insertOne(doc: any, options: { w?: any; wtimeout?: number; j?: boolean; serializeFunctions?: boolean; forceServerObjectId?: boolean }, callback?: (err: Error, result: any) => void): void; + + // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#insertMany + insertMany(docs: any, callback?: (err: Error, result: any) => void): void; + insertMany(docs: any, options: { w?: any; wtimeout?: number; j?: boolean; serializeFunctions?: boolean; forceServerObjectId?: boolean }, callback?: (err: Error, result: any) => void): void; + /** + * @deprecated use deleteOne or deleteMany + * Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#remove + */ + remove(selector: Object, callback?: (err: Error, result: any) => void): void; + remove(selector: Object, options: { safe?: any; single?: boolean; }, callback?: (err: Error, result: any) => void): void; + + // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#deleteOne + deleteOne(filter: any, callback?: (err: Error, result: any) => void): void; + deleteOne(filter: any, options: { w?: any; wtimeout?: number; j?: boolean;}, callback?: (err: Error, result: any) => void): void; + + // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#deleteMany + deleteMany(filter: any, callback?: (err: Error, result: any) => void): void; + deleteMany(filter: any, options: { w?: any; wtimeout?: number; j?: boolean;}, callback?: (err: Error, result: any) => void): void; + + rename(newName: String, callback?: (err: Error, result: any) => void): void; + + save(doc: any, callback : (err: Error, result: any) => void): void; + save(doc: any, options: { w?: any; wtimeout?: number; j?: boolean;}, callback : (err: Error, result: any) => void): void; + /** + * @deprecated use updateOne or updateMany + * Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#update + */ + update(selector: Object, document: any, callback?: (err: Error, result: any) => void): void; + update(selector: Object, document: any, options: { safe?: boolean; upsert?: any; multi?: boolean; serializeFunctions?: boolean; }, callback?: (err: Error, result: any) => void): void; + + // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#updateOne + updateOne(filter: Object, update: any, callback?: (err: Error, result: any) => void): void; + updateOne(filter: Object, update: any, options: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean;}, callback?: (err: Error, result: any) => void): void; + + // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#updateMany + updateMany(filter: Object, update: any, callback?: (err: Error, result: any) => void): void; + updateMany(filter: Object, update: any, options: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean;}, callback?: (err: Error, result: any) => void): void; + + distinct(key: string, query: Object, callback?: (err: Error, result: any) => void): void; + distinct(key: string, query: Object, options: { readPreference: string; }, callback?: (err: Error, result: any) => void): void; + + count(callback?: (err: Error, result: any) => void): void; + count(query: Object, callback?: (err: Error, result: any) => void): void; + count(query: Object, options: { readPreference: string; }, callback?: (err: Error, result: any) => void): void; + + drop(callback?: (err: Error, result: any) => void): void; + /** + * @deprecated use findOneAndUpdate, findOneAndReplace or findOneAndDelete + * Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findAndModify + */ + findAndModify(query: Object, sort: any[], doc: Object, callback?: (err: Error, result: any) => void): void; + findAndModify(query: Object, sort: any[], doc: Object, options: { safe?: any; remove?: boolean; upsert?: boolean; new?: boolean; }, callback?: (err: Error, result: any) => void): void; + /** + * @deprecated use findOneAndDelete + * Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findAndRemove + */ + findAndRemove(query : Object, sort? : any[], callback?: (err: Error, result: any) => void): void; + findAndRemove(query : Object, sort? : any[], options?: { safe: any; }, callback?: (err: Error, result: any) => void): void; + + // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findOneAndDelete + findOneAndDelete(filter: any, callback?: (err: Error, result: any) => void): void; + findOneAndDelete(filter: any, options: { projection?: any; sort?: any; maxTimeMS?: number; }, callback?: (err: Error, result: any) => void): void; + + // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findOneAndReplace + findOneAndReplace(filter: any, replacement: any, callback?: (err: Error, result: any) => void): void; + findOneAndReplace(filter: any, replacement: any, options: { projection?: any; sort?: any; maxTimeMS?: number; upsert?: boolean; returnOriginal?: boolean }, callback?: (err: Error, result: any) => void): void; + + // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findOneAndUpdate + findOneAndUpdate(filter: any, update: any, callback?: (err: Error, result: any) => void): void; + findOneAndUpdate(filter: any, update: any, options: { projection?: any; sort?: any; maxTimeMS?: number; upsert?: boolean; returnOriginal?: boolean }, callback?: (err: Error, result: any) => void): void; + + find(callback?: (err: Error, result: Cursor) => void): Cursor; + find(selector: Object, callback?: (err: Error, result: Cursor) => void): Cursor; + find(selector: Object, fields: any, callback?: (err: Error, result: Cursor) => void): Cursor; + find(selector: Object, options: CollectionFindOptions, callback?: (err: Error, result: Cursor) => void): Cursor; + find(selector: Object, fields: any, options: CollectionFindOptions, callback?: (err: Error, result: Cursor) => void): Cursor; + find(selector: Object, fields: any, skip: number, limit: number, callback?: (err: Error, result: Cursor) => void): Cursor; + find(selector: Object, fields: any, skip: number, limit: number, timeout: number, callback?: (err: Error, result: Cursor) => void): Cursor; + + findOne(callback?: (err: Error, result: any) => void): Cursor; + findOne(selector: Object, callback?: (err: Error, result: any) => void): Cursor; + findOne(selector: Object, fields: any, callback?: (err: Error, result: any) => void): Cursor; + findOne(selector: Object, options: CollectionFindOptions, callback?: (err: Error, result: any) => void): Cursor; + findOne(selector: Object, fields: any, options: CollectionFindOptions, callback?: (err: Error, result: any) => void): Cursor; + findOne(selector: Object, fields: any, skip: number, limit: number, callback?: (err: Error, result: any) => void): Cursor; + findOne(selector: Object, fields: any, skip: number, limit: number, timeout: number, callback?: (err: Error, result: any) => void): Cursor; + + createIndex(fieldOrSpec: any, callback?: (err: Error, indexName: string) => void): void; + createIndex(fieldOrSpec: any, options: IndexOptions, callback?: (err: Error, indexName: string) => void): void; + + ensureIndex(fieldOrSpec: any, callback?: (err: Error, indexName: string) => void): void; + ensureIndex(fieldOrSpec: any, options: IndexOptions, callback?: (err: Error, indexName: string) => void): void; + + indexInformation(options: any, callback?: Function): void; + dropIndex(name: string, callback?: Function): void; + dropAllIndexes(callback?: Function): void; + // dropIndexes = dropAllIndexes + + reIndex(callback?: Function): void; + mapReduce(map: Function, reduce: Function, options: MapReduceOptions, callback?: Function): void; + group(keys: Object, condition: Object, initial: Object, reduce: Function, finalize: Function, command: boolean, options: {readPreference: string}, callback?: Function): void; + options(callback?: Function): void; + isCapped(callback?: Function): void; + indexExists(indexes: string, callback?: Function): void; + geoNear(x: number, y: number, callback?: Function): void; + geoNear(x: number, y: number, options: Object, callback?: Function): void; + geoHaystackSearch(x: number, y: number, callback?: Function): void; + geoHaystackSearch(x: number, y: number, options: Object, callback?: Function): void; + indexes(callback?: Function): void; + aggregate(pipeline: any[], callback?: (err: Error, results: any) => void): void; + aggregate(pipeline: any[], options: {readPreference: string}, callback?: (err: Error, results: any) => void): void; + stats(callback?: (err: Error, results: CollStats) => void): void; + stats(options: {readPreference: string; scale: number}, callback?: (err: Error, results: CollStats) => void): void; + + hint: any; + } + + export interface MapReduceOptions { + out?: Object; + query?: Object; + sort?: Object; + limit?: number; + keeptemp?: boolean; + finalize?: any; + scope?: Object; + jsMode?: boolean; + verbose?: boolean; + readPreference?: string; + } + + export interface IndexOptions { + w?: any; + wtimeout?: number; + fsync?: boolean; + journal?: boolean; + unique?: boolean; + sparse?: boolean; + background?: boolean; + dropDups?: boolean; + min?: number; + max?: number; + v?: number; + expireAfterSeconds?: number; + name?: string; + } + + // Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/cursor.html + // Last update: doc. version 1.3.13 (29.08.2013) + export class Cursor { + // INTERNAL TYPE + // constructor (db: Db, collection: Collection, selector, fields, skip, limit, sort, hint, explain, snapshot, timeout, tailable, batchSize, slaveOk, raw, read, returnKey, maxScan, min, max, showDiskLoc, comment, awaitdata, numberOfRetries, dbName, tailableRetryInterval, exhaust, partial); + // constructor(db: Db, collection: Collection, selector, fields, options); + + rewind() : Cursor; + toArray(callback?: (err: Error, results: any[]) => any) : void; + each(callback?: (err: Error, item: any) => void) : void; + count(applySkipLimit: boolean, callback?: (err: Error, count: number) => void) : void; + + sort(keyOrList: any, callback? : (err: Error, result: any) => void): Cursor; + + // this determines how the results are sorted. "asc", "ascending" or 1 for asceding order while "desc", "desceding or -1 for descending order. Note that the strings are case insensitive. + sort(keyOrList: String, direction : string, callback : (err: Error, result: any) => void): Cursor; + limit(limit: number, callback?: (err: Error, result: any) => void): Cursor; + setReadPreference(preference: string, callback?: Function): Cursor; + skip(skip: number, callback?: (err: Error, result: any) => void): Cursor; + batchSize(batchSize: number, callback?: (err: Error, result: any) => void): Cursor; + + nextObject(callback?: (err: Error, doc: any) => void) : void; + explain(callback?: (err: Error, result: any) => void) : void; + + stream(): CursorStream; + + close(callback?: (err: Error, result: any) => void) : void; + isClosed(): boolean; + + public static INIT: number; + public static OPEN: number; + public static CLOSED: number; + public static GET_MORE: number; + } + + // Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/cursorstream.html + // Last update: doc. version 1.3.13 (29.08.2013) + export class CursorStream { + constructor(cursor: Cursor); + + public pause(): any; + public resume(): any; + public destroy(): any; + } + + export interface CollectionFindOptions { + limit?: number; + sort?: any; + fields?: Object; + skip?: number; + hint?: Object; + explain?: boolean; + snapshot?: boolean; + timeout?: boolean; + tailtable?: boolean; + tailableRetryInterval?: number; + numberOfRetries?: number; + awaitdata?: boolean; + oplogReplay?: boolean; + exhaust?: boolean; + batchSize?: number; + returnKey?: boolean; + maxScan?: number; + min?: number; + max?: number; + showDiskLoc?: boolean; + comment?: String; + raw?: boolean; + readPreference?: String; + partial?: boolean; + } + + export interface MongoCollectionOptions { + safe?: any; + serializeFunctions?: any; + strict?: boolean; + raw?: boolean; + pkFactory?: any; + readPreference?: string; + } +} diff --git a/mongodb/mongodb-tests.ts b/mongodb/mongodb-tests.ts index 9cd73d073..72589a470 100644 --- a/mongodb/mongodb-tests.ts +++ b/mongodb/mongodb-tests.ts @@ -5,25 +5,25 @@ 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) { +MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err: mongodb.MongoError, db: mongodb.Db) { if (err) throw err; var collection = db.collection('test_insert'); - collection.insert({ a: 2 }, function (err, docs) { + collection.insertOne({ a: 2 }, function(err: mongodb.MongoError, docs: any) { - collection.count(function (err, count) { + collection.count(function(err: mongodb.MongoError, count: any) { console.log(format("count = %s", count)); }); // Locate all the entries using find - collection.find().toArray(function (err, results) { + collection.find({}).toArray(function(err: mongodb.MongoError, results: any) { console.dir(results); // Let's close the db db.close(); }); // Get some statistics - collection.stats(function (err, stats) { + collection.stats(function(err: mongodb.MongoError, stats: any) { console.log(stats.count + " documents"); }); }); diff --git a/mongodb/mongodb.d.ts b/mongodb/mongodb.d.ts index 2458dbdf2..b96c43522 100644 --- a/mongodb/mongodb.d.ts +++ b/mongodb/mongodb.d.ts @@ -1,543 +1,1269 @@ -// Type definitions for MongoDB -// Project: https://github.com/mongodb/node-mongodb-native -// Definitions by: Boris Yankov +// Type definitions for MongoDB v2.1 +// Project: https://github.com/mongodb/node-mongodb-native/tree/2.1 +// Definitions by: Federico Caselli // Definitions: https://github.com/borisyankov/DefinitelyTyped -// Documentation : http://mongodb.github.io/node-mongodb-native/ +// Documentation : http://mongodb.github.io/node-mongodb-native/2.1/api/ /// +/// declare module "mongodb" { + import {EventEmitter} from 'events'; + + // Class documentation : http://mongodb.github.io/node-mongodb-native/2.1/api/MongoClient.html + export class MongoClient { + constructor(); - // 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, callback: MongoCallback): void; + static connect(uri: string, options?: MongoClientOptions): Promise; + static connect(uri: string, options: MongoClientOptions, callback: MongoCallback): void; - static connect(uri: string, callback?: (err: Error, db: Db) => void): void; - static connect(uri: string, options: any, callback?: (err: Error, db: Db) => void): void; + connect(uri: string, callback: MongoCallback): void; + connect(uri: string, options?: MongoClientOptions): Promise; + connect(uri: string, options: MongoClientOptions, callback: MongoCallback): void; } - // Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/server.html - export class Server { - constructor (host: string, port: number, opts?: ServerOptions); - - public connect(): any; + export interface MongoCallback { + (error: MongoError, result: T): void; + } + + // http://mongodb.github.io/node-mongodb-native/2.1/api/MongoError.html + export class MongoError extends Error { + constructor(message: string); + static create(options: Object): MongoError; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/MongoClient.html#.connect + export interface MongoClientOptions { + uri_decode_auth?: boolean; + db?: DbCreateOptions; + server?: ServerOptions; + replSet?: ReplSetOptions; + mongos?: MongosOptions; + promiseLibrary?: Object; + } + + // See : http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html + export interface DbCreateOptions { + authSource?: string; + // the write concern for the operation where < 1 is no acknowlegement of write and w >= 1, w = ‘majority’ or tag acknowledges the write. + w?: number | string; + // set the timeout for waiting for write concern to finish (combines with w option). + wtimeout?: number; + j?: boolean; + // use c++ bson parser. default:false. + native_parser?: boolean; + // force server to create _id fields instead of client. default:false. + forceServerObjectId?: boolean; + serializeFunctions?: boolean; + ignoreUndefined?: boolean; + // peform operations using raw bson buffers. default:false. + raw?: boolean; + // when deserializing a Long will fit it into a Number if it’s smaller than 53 bits. default:true. + promoteLongs?: boolean; + bufferMaxEntries?: number; + // the prefered read preference. use 'ReadPreference' class. + readPreference?: ReadPreference | string; + // custom primary key factory to generate _id values (see Custom primary keys). + pkFactory?: Object; + promiseLibrary?: Object; + readConcern?: { level?: Object }; } + // See http://mongodb.github.io/node-mongodb-native/2.1/api/ReadPreference.html + export class ReadPreference { + constructor(mode: string, tags: Object); + mode: string; + tags: any; + static PRIMARY: string; + static PRIMARY_PREFERRED: string; + static SECONDARY: string; + static SECONDARY_PREFERRED: string; + static NEAREST: string; + isValid(mode: string): boolean; + static isValid(mode: string): boolean; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html + export interface SocketOptions { + // Reconnect on error. default:false + autoReconnect?: boolean; + // TCP Socket NoDelay option. default:true + noDelay?: boolean; + // TCP KeepAlive on the socket with a X ms delay before start. default:0 + keepAlive?: number; + // TCP Connection timeout setting. default 0 + connectTimeoutMS?: number; + // TCP Socket timeout setting. default 0 + socketTimeoutMS?: number; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html + export interface ServerOptions { + // - specify the number of connections in the pool default:5 + poolSize?: number; + ssl?: boolean; + sslValidate?: Object; + checkServerIdentity?: boolean | Function; + sslCA?: Array; + sslCert?: Buffer | string; + sslKey?: Buffer | string; + sslPass?: Buffer | string; + socketOptions?: SocketOptions; + reconnectTries?: number; + reconnectInterval?: number; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/ReplSet.html + export interface ReplSetOptions { + ha?: boolean; + haInterval?: number; + replicaSet?: string; + secondaryAcceptableLatencyMS?: number; + connectWithNoPrimary?: boolean; + // - specify the number of connections in the pool default:5 + poolSize?: number; + ssl?: boolean; + sslValidate?: Object; + checkServerIdentity?: boolean | Function; + sslCA?: Array; + sslCert?: Buffer | string; + sslKey?: Buffer | string; + sslPass?: Buffer | string; + socketOptions?: SocketOptions; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Mongos.html + export interface MongosOptions { + ha?: boolean; + haInterval?: number; + // - specify the number of connections in the pool default:5 + poolSize?: number; + ssl?: boolean; + sslValidate?: Object; + checkServerIdentity?: boolean | Function; + sslCA?: Array; + sslCert?: Buffer | string; + sslKey?: Buffer | string; + sslPass?: Buffer | string; + socketOptions?: SocketOptions; + } + // Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/db.html - export class Db { - constructor (databaseName: string, serverConfig: Server, dbOptions?: DbCreateOptions); + export class Db extends EventEmitter { + constructor(databaseName: string, serverConfig: Server | ReplSet | Mongos, options?: DbCreateOptions); - public db(dbName: string): Db; + serverConfig: Server | ReplSet | Mongos; + bufferMaxEntries: number; + databaseName: string; + options: any; + native_parser: boolean; + slaveOk: boolean; + writeConcern: any; - public open(callback?: (err : Error, db : Db) => void ): void; - public close(forceClose?: boolean, callback?: (err: Error, result: any) => void ): void; - public admin(callback?: (err: Error, result: any) => void ): any; - public collectionsInfo(collectionName: string, callback?: (err: Error, result: any) => void ): void; - public collectionNames(collectionName: string, options: any, callback?: (err: Error, result: any) => void ): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#addUser + addUser(username: string, password: string, callback: MongoCallback): void; + addUser(username: string, password: string, options?: { w?: number | string, wtimeout?: number, j?: boolean, customData?: Object, roles?: Object[] }): Promise; + addUser(username: string, password: string, options: { w?: number | string, wtimeout?: number, j?: boolean, customData?: Object, roles?: Object[] }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#admin + admin(): Admin; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#authenticate + authenticate(userName: string, password: string, callback: MongoCallback): void; + authenticate(userName: string, password: string, options?: { authMechanism: string }): Promise; + authenticate(userName: string, password: string, options: { authMechanism: string }, callback: MongoCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#close + close(callback: MongoCallback): void; + close(forceClose?: boolean): Promise; + close(forceClose: boolean, callback: MongoCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#collection + collection(name: string): Collection; + collection(name: string, callback: MongoCallback): Collection; + collection(name: string, options: DbCollectionOptions, callback: MongoCallback): Collection; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#collections + collections(): Promise; + collections(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#command + command(command: Object, callback?: MongoCallback): void; + command(command: Object, options?: { readPreference: ReadPreference | string }): Promise; + command(command: Object, options: { readPreference: ReadPreference | string }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createCollection + createCollection(name: string, callback: MongoCallback): void; + createCollection(name: string, options?: CollectionCreateOptions): Promise; + createCollection(name: string, options: CollectionCreateOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createIndex + createIndex(name: string, fieldOrSpec: string | Object, callback: MongoCallback): void; + createIndex(name: string, fieldOrSpec: string | Object, options?: IndexOptions): Promise; + createIndex(name: string, fieldOrSpec: string | Object, options: IndexOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#db + db(dbName: string): Db; + db(dbName: string, options: { noListener?: boolean, returnNonCachedInstance?: boolean }): Db; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#dropCollection + dropCollection(name: string): Promise; + dropCollection(name: string, callback: MongoCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#dropDatabase + dropDatabase(): Promise; + dropDatabase(callback: MongoCallback): void; + + //deprecated http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#ensureIndex + // ensureIndex(collectionName: any, fieldOrSpec: any, options: IndexOptions, callback: Function): void; + //deprecated http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#eval + // eval(code: any, parameters: any[], options?: any, callback?: MongoCallback): void; + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#executeDbAdminCommand + executeDbAdminCommand(command: Object, callback: MongoCallback): void; + executeDbAdminCommand(command: Object, options?: { readPreference?: ReadPreference | string, maxTimeMS?: number }): Promise; + executeDbAdminCommand(command: Object, options: { readPreference?: ReadPreference | string, maxTimeMS?: number }, callback: MongoCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#indexInformation + indexInformation(name: string, callback: MongoCallback): void; + indexInformation(name: string, options?: { full?: boolean, readPreference?: ReadPreference | string }): Promise; + indexInformation(name: string, options: { full?: boolean, readPreference?: ReadPreference | string }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#listCollections + listCollections(filter: Object, options?: { batchSize?: number, readPreference?: ReadPreference | string }): CommandCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#logout + logout(callback: MongoCallback): void; + logout(options?: { dbName?: string }): Promise; + logout(options: { dbName?: string }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#open + open(): Promise; + open(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#removeUser + removeUser(username: string, callback: MongoCallback): void; + removeUser(username: string, options?: { w?: number | string, wtimeout?: number, j?: boolean }): Promise; + removeUser(username: string, options: { w?: number | string, wtimeout?: number, j?: boolean }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#renameCollection + renameCollection(fromCollection: string, toCollection: string, callback: MongoCallback): void; + renameCollection(fromCollection: string, toCollection: string, options?: { dropTarget?: boolean }): Promise; + renameCollection(fromCollection: string, toCollection: string, options: { dropTarget?: boolean }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#stats + stats(callback: MongoCallback): void; + stats(options?: { scale?: number }): Promise;; + stats(options: { scale?: number }, callback: MongoCallback): void; + } + + // Deprecated http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html + export class Server extends EventEmitter { + constructor(host: string, port: number, options?: ServerOptions); - public collection(collectionName: string): Collection; - public collection(collectionName: string, callback?: (err: Error, collection: Collection) => void ): Collection; - public collection(collectionName: string, options: MongoCollectionOptions, callback?: (err: Error, collection: Collection) => void ): Collection; + connections(): Array; + } + + // Deprecated http://mongodb.github.io/node-mongodb-native/2.1/api/ReplSet.html + export class ReplSet extends EventEmitter { + constructor(servers: Array, options?: ReplSetOptions); - public collections(callback?: (err: Error, collections: Collection[]) => void ): void; - public eval(code: any, parameters: any[], options?: any, callback?: (err: Error, result: any) => void ): void; - //public dereference(dbRef: DbRef, callback?: (err: Error, result: any) => void): void; + connections(): Array; + } + + // Deprecated http://mongodb.github.io/node-mongodb-native/2.1/api/ReplSet.html + export class Mongos extends EventEmitter { + constructor(servers: Array, options?: MongosOptions); - public logout(callback?: (err: Error, result: any) => void ): void; - public logout(options: any, callback?: (err: Error, result: any) => void ): void; - - public authenticate(userName: string, password: string, callback?: (err: Error, result: any) => void ): void; - public authenticate(userName: string, password: string, options: any, callback?: (err: Error, result: any) => void ): void; - - public addUser(username: string, password: string, callback?: (err: Error, result: any) => void ): void; - public addUser(username: string, password: string, options: any, callback?: (err: Error, result: any) => void ): void; - - public removeUser(username: string, callback?: (err: Error, result: any) => void ): void; - public removeUser(username: string, options: any, callback?: (err: Error, result: any) => void ): void; - - public createCollection(collectionName: string, callback?: (err: Error, result: Collection) => void ): void; - public createCollection(collectionName: string, options: CollectionCreateOptions, callback?: (err: Error, result: any) => void ): void; - - public command(selector: Object, callback?: (err: Error, result: any) => void ): void; - public command(selector: Object, options: any, callback?: (err: Error, result: any) => void ): void; - - public dropCollection(collectionName: string, callback?: (err: Error, result: any) => void ): void; - public renameCollection(fromCollection: string, toCollection: string, callback?: (err: Error, result: any) => void ): void; - - public lastError(options: Object, connectionOptions: any, callback?: (err: Error, result: any) => void ): void; - public previousError(options: Object, callback?: (err: Error, result: any) => void ): void; - - // error = lastError - // lastStatus = lastError - - public executeDbCommand(command_hash: any, callback?: (err: Error, result: any) => void ): void; - public executeDbCommand(command_hash: any, options: any, callback?: (err: Error, result: any) => void ): void; - - public executeDbAdminCommand(command_hash: any, callback?: (err: Error, result: any) => void ): void; - public executeDbAdminCommand(command_hash: any, options: any, callback?: (err: Error, result: any) => void ): void; - - public resetErrorHistory(callback?: (err: Error, result: any) => void ): void; - public resetErrorHistory(options: any, callback?: (err: Error, result: any) => void ): void; - - public createIndex(collectionName: any, fieldOrSpec: any, options: IndexOptions, callback?: Function): void; - public ensureIndex(collectionName: any, fieldOrSpec: any, options: IndexOptions, callback?: Function): void; - - public cursorInfo(options: any, callback?: Function): void; - - public dropIndex(collectionName: string, indexName: string, callback?: Function): void; - public reIndex(collectionName: string, callback?: Function): void; - public indexInformation(collectionName: string, options: any, callback?: Function): void; - public dropDatabase(callback?: (err: Error, result: any) => void ): void; - - public stats(options: any, callback?: Function): void; - public _registerHandler(db_command: any, raw: any, connection: any, exhaust: any, callback?: Function): void; - public _reRegisterHandler(newId: any, object: any, callback?: Function): void; - public _callHandler(id: any, document: any, err: any): any; - public _hasHandler(id: any): any; - public _removeHandler(id: any): any; - public _findHandler(id: any): { id: string; callback?: Function; }; - public __executeQueryCommand(self: any, db_command: any, options: any, callback?: any): void; - - public DEFAULT_URL: string; - - public connect(url: string, options: { uri_decode_auth?: boolean; }, callback?: (err: Error, result: any) => void ): void; - - public addListener(event: string, handler:(param: any) => any): any; + connections(): Array; } - // Class documentation : http://mongodb.github.io/node-mongodb-native/api-bson-generated/objectid.html - // Last update: doc. version 1.3.13 (28.08.2013) + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createCollection + export interface CollectionCreateOptions { + w?: number | string; + wtimeout?: number; + j?: boolean; + raw?: boolean; + pkFactory?: Object; + readPreference?: ReadPreference | string; + serializeFunctions?: boolean; + strict?: boolean; + capped?: boolean; + size?: number; + max?: number; + autoIndexId?: boolean; + } + + // http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#collection + export interface DbCollectionOptions { + w?: number | string; + wtimeout?: number; + j?: boolean; + raw?: boolean; + pkFactory?: Object; + readPreference?: ReadPreference | string; + serializeFunctions?: boolean; + strict?: boolean; + readConcern?: { level: Object }; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createIndex + export interface IndexOptions { + // The write concern. + w?: number | string; + // The write concern timeout. + wtimeout?: number; + // Specify a journal write concern. + j?: boolean; + // Creates an unique index. + unique?: boolean; + // Creates a sparse index. + sparse?: boolean; + // Creates the index in the background, yielding whenever possible. + background?: boolean; + // A unique index cannot be created on a key that has pre-existing duplicate values. + // If you would like to create the index anyway, keeping the first document the database indexes and + // deleting all subsequent documents that have duplicate value + dropDups?: boolean; + // For geo spatial indexes set the lower bound for the co-ordinates. + min?: number; + // For geo spatial indexes set the high bound for the co-ordinates. + max?: number; + // Specify the format version of the indexes. + v?: number; + // Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher) + expireAfterSeconds?: number; + // Override the auto generated index name (useful if the resulting name is larger than 128 bytes) + name?: string; + } + + // http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html + export class Admin { + // http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#addUser + addUser(username: string, password: string, callback: MongoCallback): void; + addUser(username: string, password: string, options?: AddUserOptions): Promise; + addUser(username: string, password: string, options: AddUserOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#authenticate + authenticate(username: string, callback: MongoCallback): void; + authenticate(username: string, password?: string): Promise; + authenticate(username: string, password: string, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#buildInfo + buildInfo(): Promise; + buildInfo(callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#command + command(command: Object, callback: MongoCallback): void; + command(command: Object, options?: { readPreference?: ReadPreference | string, maxTimeMS?: number }): Promise; + command(command: Object, options: { readPreference?: ReadPreference | string, maxTimeMS?: number }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#listDatabases + listDatabases(): Promise; + listDatabases(callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#logout + logout(): Promise; + logout(callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#ping + ping(): Promise; + ping(callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#profilingInfo + profilingInfo(): Promise; + profilingInfo(callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#profilingLevel + profilingLevel(): Promise; + profilingLevel(callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#removeUser + removeUser(username: string, callback: MongoCallback): void; + removeUser(username: string, options?: FSyncOptions): Promise; + removeUser(username: string, options: FSyncOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#replSetGetStatus + replSetGetStatus(): Promise; + replSetGetStatus(callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#serverInfo + serverInfo(): Promise; + serverInfo(callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#serverStatus + serverStatus(): Promise; + serverStatus(callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#setProfilingLevel + setProfilingLevel(level: string): Promise; + setProfilingLevel(level: string, callback: MongoCallback): void + // http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#validateCollection + validateCollection(collectionNme: string, callback: MongoCallback): void; + validateCollection(collectionNme: string, options?: Object): Promise; + validateCollection(collectionNme: string, options: Object, callback: MongoCallback): void; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#addUser + export interface AddUserOptions { + w?: number | string; + wtimeout?: number; + j?: boolean; + fsync: boolean; + customData?: Object; + roles?: Object[] + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#removeUser + export interface FSyncOptions { + w?: number | string; + wtimeout?: number; + j?: boolean; + fsync?: boolean + } + + // Class documentation : http://mongodb.github.io/node-mongodb-native/2.1/api/ObjectID.html export class ObjectID { - constructor (s?: string); - - // Returns the ObjectID id as a 24 byte hex string representation - public toHexString() : string; - - // Compares the equality of this ObjectID with otherID. - public equals(otherID: ObjectID) : boolean; - - // Returns the generation date (accurate up to the second) that this ID was generated. - public getTimestamp(): Date; - - // Creates an ObjectID from a second based number, with the rest of the ObjectID zeroed out. Used for comparisons or sorting the ObjectID. - // time – an integer number representing a number of seconds. - public static createFromTime(time: number): ObjectID; + constructor(s?: string | number); + generationTime: number; + // Creates an ObjectID from a hex string representation of an ObjectID. // hexString – create a ObjectID from a passed in 24 byte hexstring. - public static createFromHexString(hexString: string): ObjectID; - + static createFromHexString(hexString: string): ObjectID; + // Creates an ObjectID from a second based number, with the rest of the ObjectID zeroed out. Used for comparisons or sorting the ObjectID. + // time – an integer number representing a number of seconds. + static createFromTime(time: number): ObjectID; // Checks if a value is a valid bson ObjectId // id - Value to be checked - public static isValid(id: string): Boolean; - + static isValid(id: string | number): boolean; + //Compares the equality of this ObjectID with otherID. + equals(otherID: ObjectID): boolean; // Generate a 12 byte id string used in ObjectID's // time - optional parameter allowing to pass in a second based timestamp - public generate(time?: number): string; + generate(time?: number): string; + // Returns the generation date (accurate up to the second) that this ID was generated. + getTimestamp(): Date; + // Returns the ObjectID id as a 24 byte hex string representation + toHexString(): string; } - // Class documentation : http://mongodb.github.io/node-mongodb-native/api-bson-generated/binary.html + // Class documentation : http://mongodb.github.io/node-mongodb-native/2.1/api/Binary.html export class Binary { - constructor (buffer: Buffer, subType?: number); + constructor(buffer: Buffer, subType?: number); - // Updates this binary with byte_value - put(byte_value: any): void; - - // Writes a buffer or string to the binary - write(buffer: any, offset: number): void; - - // Reads length bytes starting at position. - read(position: number, length: number): Buffer; - - // Returns the value of this binary as a string. - value(): string; + static SUBTYPE_BYTE_ARRAY: number; + static SUBTYPE_DEFAULT: number; + static SUBTYPE_FUNCTION: number; + static SUBTYPE_MD5: number; + static SUBTYPE_USER_DEFINED: number; + static SUBTYPE_UUID: number; + static SUBTYPE_UUID_OLD: number; // The length of the binary. length(): number; + // Updates this binary with byte_value + put(byte_value: number | string): void; + // Reads length bytes starting at position. + read(position: number, length: number): Buffer; + // Returns the value of this binary as a string. + value(): string; + // Writes a buffer or string to the binary + write(buffer: Buffer | string, offset: number): void; + } + //http://mongodb.github.io/node-mongodb-native/2.1/api/Double.html + export class Double { + constructor(value: number); + + valueOf(): number; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Long.html + export class Long { + constructor(low: number, high: number); + + static MAX_VALUE: Long; + static MIN_VALUE: Long; + static NEG_ONE: Long; + static ONE: Long; + static ZERO: Long; + + static fromBits(lowBits: number, highBits: number): Long; + static fromInt(value: number): Long; + static fromNumber(value: number): Long; + static fromString(str: string, radix?: number): Long; + + add(other: Long): Long; + and(other: Long): Long; + compare(other: Long): number; + div(other: Long): Long; + equals(other: Long): boolean; + getHighBits(): number; + getLowBits(): number; + getLowBitsUnsigned(): number; + getNumBitsAbs(): number; + greaterThan(other: Long): number; + greaterThanOrEqual(other: Long): number; + isNegative(): boolean; + isOdd(): boolean; + isZero(): boolean; + lessThan(other: Long): boolean; + lessThanOrEqual(other: Long): boolean; + modulo(other: Long): Long; + multiply(other: Long): Long; + negate(): Long; + not(): Long; + notEquals(other: Long): boolean; + or(other: Long): Long; + shiftLeft(other: number): Long; + shiftRight(other: number): Long; + shiftRightUnsigned(other: number): Long; + subtract(other: Long): Long; + toInt(): number; + toJSON(): string; + toNumber(): number; + toString(radix?: number): string; + xor(other: Long): Long; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/MaxKey.html + export class MaxKey { } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/MinKey.html + export class MinKey { } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Timestamp.html + export class Timestamp { + constructor(low: number, high: number); + + static MAX_VALUE: Timestamp; + static MIN_VALUE: Timestamp; + static NEG_ONE: Timestamp; + static ONE: Timestamp; + static ZERO: Timestamp; + + static fromBits(lowBits: number, highBits: number): Timestamp; + static fromInt(value: number): Timestamp; + static fromNumber(value: number): Timestamp; + static fromString(str: string, radix?: number): Timestamp; + + add(other: Timestamp): Timestamp; + and(other: Timestamp): Timestamp; + compare(other: Timestamp): number; + div(other: Timestamp): Timestamp; + equals(other: Timestamp): boolean; + getHighBits(): number; + getLowBits(): number; + getLowBitsUnsigned(): number; + getNumBitsAbs(): number; + greaterThan(other: Timestamp): number; + greaterThanOrEqual(other: Timestamp): number; + isNegative(): boolean; + isOdd(): boolean; + isZero(): boolean; + lessThan(other: Timestamp): boolean; + lessThanOrEqual(other: Timestamp): boolean; + modulo(other: Timestamp): Timestamp; + multiply(other: Timestamp): Timestamp; + negate(): Timestamp; + not(): Timestamp; + notEquals(other: Timestamp): boolean; + or(other: Timestamp): Timestamp; + shiftLeft(other: number): Timestamp; + shiftRight(other: number): Timestamp; + shiftRightUnsigned(other: number): Timestamp; + subtract(other: Timestamp): Timestamp; + toInt(): number; + toJSON(): string; + toNumber(): number; + toString(radix?: number): string; + xor(other: Timestamp): Timestamp; } - export interface SocketOptions { - //= set seconds before connection times out default:0 - timeout?: number; - //= Disables the Nagle algorithm default:true - noDelay?: boolean; - //= Set if keepAlive is used default:0 , which means no keepAlive, set higher than 0 for keepAlive - keepAlive?: number; - //= ‘ascii’|’utf8’|’base64’ default:null - encoding?: string; + // Documentation : http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html + export class Collection { + // Get the collection name. + collectionName: string; + // Get the full collection namespace. + namespace: string; + // The current write concern values. + writeConcern: any; + // The current read concern values. + readConcern: any; + // Get current index hint for collection. + hint: any; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#aggregate + aggregate(pipeline: Object[], callback: MongoCallback): void | AggregationCursor; + aggregate(pipeline: Object[], options: CollectionAggrigationOptions, callback: MongoCallback): void | AggregationCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#bulkWrite + bulkWrite(operations: Object[], callback: MongoCallback): void + bulkWrite(operations: Object[], options?: CollectionBluckWriteOptions): Promise + bulkWrite(operations: Object[], options: CollectionBluckWriteOptions, callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#count + count(query: Object, callback: MongoCallback): void; + count(query: Object, options?: MongoCountPreferences): Promise; + count(query: Object, options: MongoCountPreferences, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#createIndex + createIndex(fieldOrSpec: string | any, callback: MongoCallback): void; + createIndex(fieldOrSpec: string | any, options?: IndexOptions): Promise; + createIndex(fieldOrSpec: string | any, options: IndexOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#createIndexes and http://docs.mongodb.org/manual/reference/command/createIndexes/ + createIndexes(indexSpecs: Object[]): Promise; + createIndexes(indexSpecs: Object[], callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#deleteMany + deleteMany(filter: Object, callback: MongoCallback): void; + deleteMany(filter: Object, options?: CollectionOptions): Promise; + deleteMany(filter: Object, options: CollectionOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#deleteOne + deleteOne(filter: Object, callback: MongoCallback): void; + deleteOne(filter: Object, options?: { w?: number | string, wtimmeout?: number, j?: boolean, bypassDocumentValidation?: boolean }): Promise; + deleteOne(filter: Object, options: { w?: number | string, wtimmeout?: number, j?: boolean, bypassDocumentValidation?: boolean }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#distinct + distinct(key: string, query: Object, callback: MongoCallback): void + distinct(key: string, query: Object, options?: { readPreference?: ReadPreference | string }): Promise; + distinct(key: string, query: Object, options: { readPreference?: ReadPreference | string }, callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#drop + drop(): Promise; + drop(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#dropIndex + dropIndex(indexName: string, callback: MongoCallback): void; + dropIndex(indexName: string, options?: CollectionOptions): Promise; + dropIndex(indexName: string, options: CollectionOptions, callback: MongoCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#dropIndexes + dropIndexes(): Promise; + dropIndexes(callback?: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#find + find(query: Object): Cursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#findOneAndDelete + findOneAndDelete(filter: Object, callback: MongoCallback): void; + findOneAndDelete(filter: Object, options?: { projection?: Object, sort?: Object, maxTimeMS?: number }): Promise; + findOneAndDelete(filter: Object, options: { projection?: Object, sort?: Object, maxTimeMS?: number }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#findOneAndReplace + findOneAndReplace(filter: Object, replacement: Object, callback: MongoCallback): void; + findOneAndReplace(filter: Object, replacement: Object, options?: FindOneAndReplaceOption): Promise; + findOneAndReplace(filter: Object, replacement: Object, options: FindOneAndReplaceOption, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#findOneAndUpdate + findOneAndUpdate(filter: Object, update: Object, callback: MongoCallback): void; + findOneAndUpdate(filter: Object, update: Object, options?: FindOneAndReplaceOption): Promise; + findOneAndUpdate(filter: Object, update: Object, options: FindOneAndReplaceOption, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#geoHaystackSearch + geoHaystackSearch(x: number, y: number, callback: MongoCallback): void; + geoHaystackSearch(x: number, y: number, options?: GeoHaystackSearchOptions): Promise; + geoHaystackSearch(x: number, y: number, options: GeoHaystackSearchOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#geoNear + geoNear(x: number, y: number, callback: MongoCallback): void; + geoNear(x: number, y: number, options?: GeoNearOptions): Promise; + geoNear(x: number, y: number, options: GeoNearOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#group + group(keys: Object | Array | Function | Code, condition: Object, initial: Object, reduce: Function | Code, finalize: Function | Code, command: boolean, callback: MongoCallback): void; + group(keys: Object | Array | Function | Code, condition: Object, initial: Object, reduce: Function | Code, finalize: Function | Code, command: boolean, options?: { readPreference?: ReadPreference | string }): Promise; + group(keys: Object | Array | Function | Code, condition: Object, initial: Object, reduce: Function | Code, finalize: Function | Code, command: boolean, options: { readPreference?: ReadPreference | string }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#indexes + indexes(): Promise; + indexes(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#indexExists + indexExists(indexes: string | string[]): Promise; + indexExists(indexes: string | string[], callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#indexInformation + indexInformation(callback: MongoCallback): void; + indexInformation(options?: { full: boolean }): Promise; + indexInformation(options: { full: boolean }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#initializeOrderedBulkOp + initializeOrderedBulkOp(options: CollectionOptions): OrderedBulkOperation; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#initializeUnorderedBulkOp + initializeOrderedBulkOp(options: CollectionOptions): OrderedBulkOperation; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#insertMany + insertMany(docs: Object[], callback: MongoCallback): void + insertMany(docs: Object[], options?: CollectionInsertManyOptions): Promise; + insertMany(docs: Object[], options: CollectionInsertManyOptions, callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#insertOne + insertOne(docs: Object, callback: MongoCallback): void + insertOne(docs: Object, options?: CollectionInsertOneOptions): Promise; + insertOne(docs: Object, options: CollectionInsertOneOptions, callback: MongoCallback): void + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#isCapped + isCapped(): Promise; + isCapped(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#listIndexes + listIndexes(options?: { batchSize?: number, readPreference?: ReadPreference | string }): CommandCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#mapReduce + mapReduce(map: Function | string, reduce: Function | string, callback: MongoCallback): void; + mapReduce(map: Function | string, reduce: Function | string, options?: MapReduceOptions): Promise; + mapReduce(map: Function | string, reduce: Function | string, options: MapReduceOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#options + options(): Promise; + options(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#parallelCollectionScan + parallelCollectionScan(callback: MongoCallback): void; + parallelCollectionScan(options?: ParallelCollectionScanOptions): Promise; + parallelCollectionScan(options: ParallelCollectionScanOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#reIndex + reIndex(): Promise; + reIndex(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#rename + rename(newName: string, callback: MongoCallback): void; + rename(newName: string, options?: { dropTarget?: boolean }): Promise; + rename(newName: string, options: { dropTarget?: boolean }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#replaceOne + replaceOne(filter: Object, doc: Object, callback: MongoCallback): void; + replaceOne(filter: Object, doc: Object, options?: ReplaceOneOptions): Promise; + replaceOne(filter: Object, doc: Object, options: ReplaceOneOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#stats + stats(callback: MongoCallback): void; + stats(options?: { scale: number }): Promise; + stats(options: { scale: number }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#updateMany + updateMany(filter: Object, update: Object, callback: MongoCallback): void; + updateMany(filter: Object, update: Object, options?: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean; }): Promise; + updateMany(filter: Object, update: Object, options: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean; }, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#updateOne + updateOne(filter: Object, update: Object, callback: MongoCallback): void; + updateOne(filter: Object, update: Object, options?: ReplaceOneOptions): Promise; + updateOne(filter: Object, update: Object, options: ReplaceOneOptions, callback: MongoCallback): void; } - - export interface ServerOptions { - // - to reconnect automatically, default:false - auto_reconnect?: boolean; - // - specify the number of connections in the pool default:1 - poolSize?: number; - // - a collection of pr socket settings - socketOptions?: any; - } - - export interface PKFactory { - counter: number; - createPk: () => number; - } - - // See : http://mongodb.github.io/node-mongodb-native/api-generated/db.html - // Current definition by documentation version 1.3.13 (28.08.2013) - export interface DbCreateOptions { - // the write concern for the operation where < 1 is no acknowlegement of write and w >= 1, w = ‘majority’ or tag acknowledges the write. - w?: any; - - // set the timeout for waiting for write concern to finish (combines with w option). - wtimeout?: number; - - // write waits for fsync before returning. default:false. - fsync?: boolean; - - // write waits for journal sync before returning. default:false. - journal?: boolean; - - // the prefered read preference. use 'ReadPreference' class. - readPreference?: string; - - // use c++ bson parser. default:false. - native_parser?: boolean; - - // force server to create _id fields instead of client. default:false. - forceServerObjectId?: boolean; - - // custom primary key factory to generate _id values (see Custom primary keys). - pkFactory?: PKFactory; - - // serialize functions. default:false. - serializeFunctions?: boolean; - - // peform operations using raw bson buffers. default:false. - raw?: boolean; - - // record query statistics during execution. default:false. - recordQueryStats?: boolean; - - // number of miliseconds between retries. default:5000. - retryMiliSeconds?: number; - - // number of retries off connection. default:5. - numberOfRetries?: number; - - // an object representing a logger that you want to use, needs to support functions debug, log, error. default:null. - logger?: Object - - // force setting of SlaveOk flag on queries (only use when explicitly connecting to a secondary server). default:null. - slaveOk?: number; - - // when deserializing a Long will fit it into a Number if it’s smaller than 53 bits. default:true. - promoteLongs?: boolean; - } - - export class ReadPreference { - public static PRIMARY: string; - public static PRIMARY_PREFERRED: string; - public static SECONDARY: string; - public static SECONDARY_PREFERRED: string; - public static NEAREST: string; - } - - // See : http://mongodb.github.io/node-mongodb-native/api-generated/collection.html - // Current definition by documentation version 1.3.13 (28.08.2013) - export interface CollectionCreateOptions { - // the prefered read preference. use 'ReadPreference' class. - readPreference?: string; - - // Allow reads from secondaries. default:false. - slaveOk?: boolean; - - // serialize functions on the document. default:false. - serializeFunctions?: boolean; - - // perform all operations using raw bson objects. default:false. - raw?: boolean; - - // object overriding the basic ObjectID primary key generation. - pkFactory?: PKFactory; - } - + // Documentation: http://docs.mongodb.org/manual/reference/command/collStats/ export interface CollStats { // Namespace. ns: string; - // Number of documents. count: number; - // Collection size in bytes. size: number; - // Average object size in bytes. avgObjSize: number; - // (Pre)allocated space for the collection in bytes. storageSize: number; - // Number of extents (contiguously allocated chunks of datafile space). numExtents: number; - // Number of indexes. nindexes: number; - // Size of the most recently created extent in bytes. lastExtentSize: number; - // Padding can speed up updates if documents grow. paddingFactor: number; - flags: number; - - // Total index size in bytes. + userFlags: number; + // Total index size in bytes. totalIndexSize: number; - // Size of specific indexes in bytes. indexSizes: { - _id_: number; - username: number; + _id_: number; + username: number; }; + capped: boolean; + maxSize: boolean; + wiredTiger: any; + indexDetails: any; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#aggregate + export interface CollectionAggrigationOptions { + readPreference?: ReadPreference | string; + // Return the query as cursor, on 2.6 > it returns as a real cursor + // on pre 2.6 it returns as an emulated cursor. + cursor?: { batchSize: number }; + // Explain returns the aggregation execution plan (requires mongodb 2.6 >). + explain?: boolean; + // lets the server know if it can use disk to store + // temporary results for the aggregation (requires mongodb 2.6 >). + allowDiskUse?: boolean; + // specifies a cumulative time limit in milliseconds for processing operations + // on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. + maxTimeMS?: boolean; + // Allow driver to bypass schema validation in MongoDB 3.2 or higher. + bypassDocumentValidation?: boolean; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#insertMany + export interface CollectionInsertManyOptions { + // The write concern. + w?: number | string; + // The write concern timeout. + wtimeout?: number; + // Specify a journal write concern. + j?: boolean; + // Serialize functions on any object. + serializeFunctions?: boolean; + //Force server to assign _id values instead of driver. + forceServerObjectId?: boolean; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#bulkWrite + export interface CollectionBluckWriteOptions { + // The write concern. + w?: number | string; + // The write concern timeout. + wtimeout?: number; + // Specify a journal write concern. + j?: boolean; + // Serialize functions on any object. + serializeFunctions?: boolean; + // Execute write operation in ordered or unordered fashion. + ordered?: boolean; + // Allow driver to bypass schema validation in MongoDB 3.2 or higher. + bypassDocumentValidation?: boolean; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#~BulkWriteOpResult + export interface BulkWriteOpResultObject { + insertedCount?: number; + matchedCount?: number; + modifiedCount?: number; + deletedCount?: number; + upsertedCount?: number; + insertedIds?: any; + upsertedIds?: any; + result?: any; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#count + export interface MongoCountPreferences { + // The limit of documents to count. + limit?: number; + // The number of documents to skip for the count. + skip?: boolean; + // An index name hint for the query. + hint?: string; + // The preferred read preference + readPreference?: ReadPreference | string; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#~deleteWriteOpResult + export interface DeleteWriteOpResultObject { + //The raw result returned from MongoDB, field will vary depending on server version. + result: { + //Is 1 if the command executed correctly. + ok?: number; + //The total count of documents deleted. + n?: number; + } + //The connection object used for the operation. + connection?: any; + //The number of documents deleted. + deletedCount?: number; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#~findAndModifyWriteOpResult + export interface FindAndModifyWriteOpResultObject { + //Document returned from findAndModify command. + value?: any; + //The raw lastErrorObject returned from the command. + lastErrorObject?: any; + //Is 1 if the command executed correctly. + ok?: number; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#findOneAndReplace + export interface FindOneAndReplaceOption { + projection?: Object; + sort?: Object; + maxTimeMS?: number; + upsert?: boolean; + returnOriginal?: boolean; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#geoHaystackSearch + export interface GeoHaystackSearchOptions { + readPreference?: ReadPreference | string; + maxDistance?: number; + search?: Object; + limit?: number; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#geoNear + export interface GeoNearOptions { + readPreference?: ReadPreference | string; + num?: number; + minDistance?: number; + maxDistance?: number; + distanceMultiplier?: number; + query?: Object; + spherical?: boolean; + uniqueDocs?: boolean; + includeLocs?: boolean; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Code.html + export class Code { + constructor(code: string | Function, scope?: Object) + code: string | Function; + scope: any; } - // Documentation : http://mongodb.github.io/node-mongodb-native/api-generated/collection.html - export interface Collection { - new (db: Db, collectionName: string, pkFactory?: Object, options?: CollectionCreateOptions): Collection; // is this right? - /** - * @deprecated use insertOne or insertMany - * Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#insert - */ - insert(query: any, callback?: (err: Error, result: any) => void): void; - insert(query: any, options: { safe?: any; continueOnError?: boolean; keepGoing?: boolean; serializeFunctions?: boolean; }, callback?: (err: Error, result: any) => void): void; - - // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#insertOne - insertOne(doc:any, callback?: (err: Error, result: any) => void) :void; - insertOne(doc: any, options: { w?: any; wtimeout?: number; j?: boolean; serializeFunctions?: boolean; forceServerObjectId?: boolean }, callback?: (err: Error, result: any) => void): void; - - // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#insertMany - insertMany(docs: any, callback?: (err: Error, result: any) => void): void; - insertMany(docs: any, options: { w?: any; wtimeout?: number; j?: boolean; serializeFunctions?: boolean; forceServerObjectId?: boolean }, callback?: (err: Error, result: any) => void): void; - /** - * @deprecated use deleteOne or deleteMany - * Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#remove - */ - remove(selector: Object, callback?: (err: Error, result: any) => void): void; - remove(selector: Object, options: { safe?: any; single?: boolean; }, callback?: (err: Error, result: any) => void): void; - - // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#deleteOne - deleteOne(filter: any, callback?: (err: Error, result: any) => void): void; - deleteOne(filter: any, options: { w?: any; wtimeout?: number; j?: boolean;}, callback?: (err: Error, result: any) => void): void; - - // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#deleteMany - deleteMany(filter: any, callback?: (err: Error, result: any) => void): void; - deleteMany(filter: any, options: { w?: any; wtimeout?: number; j?: boolean;}, callback?: (err: Error, result: any) => void): void; - - rename(newName: String, callback?: (err: Error, result: any) => void): void; - - save(doc: any, callback : (err: Error, result: any) => void): void; - save(doc: any, options: { w?: any; wtimeout?: number; j?: boolean;}, callback : (err: Error, result: any) => void): void; - /** - * @deprecated use updateOne or updateMany - * Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#update - */ - update(selector: Object, document: any, callback?: (err: Error, result: any) => void): void; - update(selector: Object, document: any, options: { safe?: boolean; upsert?: any; multi?: boolean; serializeFunctions?: boolean; }, callback?: (err: Error, result: any) => void): void; - - // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#updateOne - updateOne(filter: Object, update: any, callback?: (err: Error, result: any) => void): void; - updateOne(filter: Object, update: any, options: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean;}, callback?: (err: Error, result: any) => void): void; - - // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#updateMany - updateMany(filter: Object, update: any, callback?: (err: Error, result: any) => void): void; - updateMany(filter: Object, update: any, options: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean;}, callback?: (err: Error, result: any) => void): void; - - distinct(key: string, query: Object, callback?: (err: Error, result: any) => void): void; - distinct(key: string, query: Object, options: { readPreference: string; }, callback?: (err: Error, result: any) => void): void; - - count(callback?: (err: Error, result: any) => void): void; - count(query: Object, callback?: (err: Error, result: any) => void): void; - count(query: Object, options: { readPreference: string; }, callback?: (err: Error, result: any) => void): void; - - drop(callback?: (err: Error, result: any) => void): void; - /** - * @deprecated use findOneAndUpdate, findOneAndReplace or findOneAndDelete - * Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findAndModify - */ - findAndModify(query: Object, sort: any[], doc: Object, callback?: (err: Error, result: any) => void): void; - findAndModify(query: Object, sort: any[], doc: Object, options: { safe?: any; remove?: boolean; upsert?: boolean; new?: boolean; }, callback?: (err: Error, result: any) => void): void; - /** - * @deprecated use findOneAndDelete - * Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findAndRemove - */ - findAndRemove(query : Object, sort? : any[], callback?: (err: Error, result: any) => void): void; - findAndRemove(query : Object, sort? : any[], options?: { safe: any; }, callback?: (err: Error, result: any) => void): void; - - // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findOneAndDelete - findOneAndDelete(filter: any, callback?: (err: Error, result: any) => void): void; - findOneAndDelete(filter: any, options: { projection?: any; sort?: any; maxTimeMS?: number; }, callback?: (err: Error, result: any) => void): void; - - // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findOneAndReplace - findOneAndReplace(filter: any, replacement: any, callback?: (err: Error, result: any) => void): void; - findOneAndReplace(filter: any, replacement: any, options: { projection?: any; sort?: any; maxTimeMS?: number; upsert?: boolean; returnOriginal?: boolean }, callback?: (err: Error, result: any) => void): void; - - // Documentation : http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findOneAndUpdate - findOneAndUpdate(filter: any, update: any, callback?: (err: Error, result: any) => void): void; - findOneAndUpdate(filter: any, update: any, options: { projection?: any; sort?: any; maxTimeMS?: number; upsert?: boolean; returnOriginal?: boolean }, callback?: (err: Error, result: any) => void): void; - - find(callback?: (err: Error, result: Cursor) => void): Cursor; - find(selector: Object, callback?: (err: Error, result: Cursor) => void): Cursor; - find(selector: Object, fields: any, callback?: (err: Error, result: Cursor) => void): Cursor; - find(selector: Object, options: CollectionFindOptions, callback?: (err: Error, result: Cursor) => void): Cursor; - find(selector: Object, fields: any, options: CollectionFindOptions, callback?: (err: Error, result: Cursor) => void): Cursor; - find(selector: Object, fields: any, skip: number, limit: number, callback?: (err: Error, result: Cursor) => void): Cursor; - find(selector: Object, fields: any, skip: number, limit: number, timeout: number, callback?: (err: Error, result: Cursor) => void): Cursor; - - findOne(callback?: (err: Error, result: any) => void): Cursor; - findOne(selector: Object, callback?: (err: Error, result: any) => void): Cursor; - findOne(selector: Object, fields: any, callback?: (err: Error, result: any) => void): Cursor; - findOne(selector: Object, options: CollectionFindOptions, callback?: (err: Error, result: any) => void): Cursor; - findOne(selector: Object, fields: any, options: CollectionFindOptions, callback?: (err: Error, result: any) => void): Cursor; - findOne(selector: Object, fields: any, skip: number, limit: number, callback?: (err: Error, result: any) => void): Cursor; - findOne(selector: Object, fields: any, skip: number, limit: number, timeout: number, callback?: (err: Error, result: any) => void): Cursor; - - createIndex(fieldOrSpec: any, callback?: (err: Error, indexName: string) => void): void; - createIndex(fieldOrSpec: any, options: IndexOptions, callback?: (err: Error, indexName: string) => void): void; - - ensureIndex(fieldOrSpec: any, callback?: (err: Error, indexName: string) => void): void; - ensureIndex(fieldOrSpec: any, options: IndexOptions, callback?: (err: Error, indexName: string) => void): void; - - indexInformation(options: any, callback?: Function): void; - dropIndex(name: string, callback?: Function): void; - dropAllIndexes(callback?: Function): void; - // dropIndexes = dropAllIndexes - - reIndex(callback?: Function): void; - mapReduce(map: Function, reduce: Function, options: MapReduceOptions, callback?: Function): void; - group(keys: Object, condition: Object, initial: Object, reduce: Function, finalize: Function, command: boolean, options: {readPreference: string}, callback?: Function): void; - options(callback?: Function): void; - isCapped(callback?: Function): void; - indexExists(indexes: string, callback?: Function): void; - geoNear(x: number, y: number, callback?: Function): void; - geoNear(x: number, y: number, options: Object, callback?: Function): void; - geoHaystackSearch(x: number, y: number, callback?: Function): void; - geoHaystackSearch(x: number, y: number, options: Object, callback?: Function): void; - indexes(callback?: Function): void; - aggregate(pipeline: any[], callback?: (err: Error, results: any) => void): void; - aggregate(pipeline: any[], options: {readPreference: string}, callback?: (err: Error, results: any) => void): void; - stats(callback?: (err: Error, results: CollStats) => void): void; - stats(options: {readPreference: string; scale: number}, callback?: (err: Error, results: CollStats) => void): void; - - hint: any; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#deleteMany + export interface CollectionOptions { + //The write concern. + w?: number | string; + //The write concern timeout. + wtimeout?: number; + //Specify a journal write concern. + j?: boolean; } - + + //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html + export class OrderedBulkOperation { + length: number; + //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html#execute + execute(callback: MongoCallback): void; + execute(options: FSyncOptions): Promise; + execute(options: FSyncOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html#find + find(selector: Object): FindOperatorsOrdered; + //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html#insert + insert(doc: Object): OrderedBulkOperation; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/BulkWriteResult.html + export class BulkWriteResult { + getInsertedIds(): Array; + getLastOp(): Object; + getRawResponse(): Object; + getUpsertedIdAt(index: number): Object; + getUpsertedIds(): Array; + getWriteConcernError(): WriteConcernError; + getWriteErrorAt(index: number): WriteError; + getWriteErrorCount(): number; + getWriteErrors(): Array; + hasWriteErrors(): boolean; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/WriteError.html + export interface WriteError { + //Write concern error code. + code: number; + //Write concern error original bulk operation index. + index: number; + //Write concern error message. + errmsg: string; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/WriteConcernError.html + export interface WriteConcernError { + //Write concern error code. + code: number; + //Write concern error message. + errmsg: string; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/FindOperatorsOrdered.html + export class FindOperatorsOrdered { + delete(): OrderedBulkOperation; + deleteOne(): OrderedBulkOperation; + replaceOne(doc: Object): OrderedBulkOperation; + update(doc: Object): OrderedBulkOperation; + updateOne(doc: Object): OrderedBulkOperation; + upsert(): FindOperatorsOrdered; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html + export class UnorderedBulkOperation { + //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html#execute + execute(callback: MongoCallback): void; + execute(options: FSyncOptions): Promise; + execute(options: FSyncOptions, callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html#find + find(selector: Object): FindOperatorsUnordered; + //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html#insert + insert(doc: Object): UnorderedBulkOperation; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/FindOperatorsUnordered.html + export class FindOperatorsUnordered { + length: number; + remove(): UnorderedBulkOperation; + removeOne(): UnorderedBulkOperation; + replaceOne(doc: Object): UnorderedBulkOperation; + update(doc: Object): UnorderedBulkOperation; + updateOne(doc: Object): UnorderedBulkOperation; + upsert(): FindOperatorsUnordered; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#~insertWriteOpResult + export interface InsertWriteOpResult { + insertedCount: number; + ops: Array; + insertedIds: Array; + connection: any; + result: { ok: number, n: number } + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#insertOne + export interface CollectionInsertOneOptions { + // The write concern. + w?: number | string; + // The write concern timeout. + wtimeout?: number; + // Specify a journal write concern. + j?: boolean; + // Serialize functions on any object. + serializeFunctions?: boolean; + //Force server to assign _id values instead of driver. + forceServerObjectId?: boolean; + //Allow driver to bypass schema validation in MongoDB 3.2 or higher. + bypassDocumentValidation?: boolean + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#~insertOneWriteOpResult + export interface InsertOneWriteOpResult { + insertedCount: number; + ops: Array; + insertedId: ObjectID; + connection: any; + result: { ok: number, n: number } + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#parallelCollectionScan + export interface ParallelCollectionScanOptions { + readPreference?: ReadPreference | string; + batchSize?: number; + numCursors?: number; + raw?: boolean; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#replaceOne + export interface ReplaceOneOptions { + upsert?: boolean; + w?: number | string; + wtimeout?: number; + j?: boolean; + bypassDocumentValidation?: boolean; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#~updateWriteOpResult + export interface UpdateWriteOpResult { + result: { ok: number, n: number, nModified: number }; + connection: any; + matchedCount: number; + modifiedCount: number; + upsertedCount: number; + upsertedId: { _id: ObjectID }; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#mapReduce export interface MapReduceOptions { + readPreference?: ReadPreference | string; out?: Object; query?: Object; sort?: Object; limit?: number; keeptemp?: boolean; - finalize?: any; + finalize?: Function | string; scope?: Object; jsMode?: boolean; verbose?: boolean; - readPreference?: string; + bypassDocumentValidation?: boolean + } + + + //http://mongodb.github.io/node-mongodb-native/2.1/api/external-Readable.html + export interface Readable { + pause(): void; + pipe(destination: Writable, options?: Object): void; + read(size: number): string | Buffer | void; + resume(): void; + setEncoding(encoding: string): void; + unpipe(destination?: Writable): void; + unshift(stream: Buffer | string): void; + wrap(stream: Stream): void; } - export interface IndexOptions { - w?: any; - wtimeout?: number; - fsync?: boolean; - journal?: boolean; - unique?: boolean; - sparse?: boolean; - background?: boolean; - dropDups?: boolean; - min?: number; - max?: number; - v?: number; - expireAfterSeconds?: number; - name?: string; - } + export interface Writable { } + export interface Stream { } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#~resultCallback + export type CursorResult = any | void | boolean; + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html + export class Cursor extends EventEmitter implements Readable { - // Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/cursor.html - // Last update: doc. version 1.3.13 (29.08.2013) - export class Cursor { - // INTERNAL TYPE - // constructor (db: Db, collection: Collection, selector, fields, skip, limit, sort, hint, explain, snapshot, timeout, tailable, batchSize, slaveOk, raw, read, returnKey, maxScan, min, max, showDiskLoc, comment, awaitdata, numberOfRetries, dbName, tailableRetryInterval, exhaust, partial); - // constructor(db: Db, collection: Collection, selector, fields, options); - - rewind() : Cursor; - toArray(callback?: (err: Error, results: any[]) => any) : void; - each(callback?: (err: Error, item: any) => void) : void; - count(applySkipLimit: boolean, callback?: (err: Error, count: number) => void) : void; - - sort(keyOrList: any, callback? : (err: Error, result: any) => void): Cursor; - - // this determines how the results are sorted. "asc", "ascending" or 1 for asceding order while "desc", "desceding or -1 for descending order. Note that the strings are case insensitive. - sort(keyOrList: String, direction : string, callback : (err: Error, result: any) => void): Cursor; - limit(limit: number, callback?: (err: Error, result: any) => void): Cursor; - setReadPreference(preference: string, callback?: Function): Cursor; - skip(skip: number, callback?: (err: Error, result: any) => void): Cursor; - batchSize(batchSize: number, callback?: (err: Error, result: any) => void): Cursor; - - nextObject(callback?: (err: Error, doc: any) => void) : void; - explain(callback?: (err: Error, result: any) => void) : void; - - stream(): CursorStream; - - close(callback?: (err: Error, result: any) => void) : void; + sortValue: string; + timeout: boolean; + readPreference: ReadPreference; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html + addCursorFlag(flag: string, value: boolean): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#addQueryModifier + addQueryModifier(name: string, value: boolean): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#batchSize + batchSize(value: number): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#clone + clone(): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#close + close(): Promise; + close(callback: MongoCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#comment + comment(value: string): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#count + count(applySkipLimit: boolean, callback: MongoCallback): void; + count(applySkipLimit: boolean, options?: CursorCommentOptions): Promise; + count(applySkipLimit: boolean, options: CursorCommentOptions, callback: MongoCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#explain + explain(): Promise; + explain(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#filter + filter(filter: Object): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#forEach + forEach(iterator: IteratorCallback, callback: EndCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#hasNext + hasNext(): Promise; + hasNext(callback: MongoCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#hint + hint(hint: Object): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#isClosed isClosed(): boolean; - - public static INIT: number; - public static OPEN: number; - public static CLOSED: number; - public static GET_MORE: number; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#limit + limit(value: number): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#map + map(transform: Function): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#max + max(max: number): Cursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#maxAwaitTimeMS + maxAwaitTimeMS(value: number): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#maxScan + maxScan(maxScan: Object): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#maxTimeMS + maxTimeMS(value: number): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#min + min(min: number): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#next + next(): Promise; + next(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#pause + pause(): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#pipe + pipe(destination: Writable, options?: Object): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#project + project(value: Object): Cursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#read + read(size: number): string | Buffer | void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#resume + resume(): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#next + returnKey(returnKey: Object): Cursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#rewind + rewind(): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#setCursorOption + setCursorOption(field: string, value: Object): Cursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#setEncoding + setEncoding(encoding: string): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#setReadPreference + setReadPreference(readPreference: string | ReadPreference): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#showRecordId + showRecordId(showRecordId: Object): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#skip + skip(value: number): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#snapshot + snapshot(snapshot: Object): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#sort + sort(keyOrList: string | Object[] | Object | Object, direction?: number): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#stream + stream(options?: { transform?: Function }): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#toArray + toArray(): Promise; + toArray(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#unpipe + unpipe(destination?: Writable): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#unshift + unshift(stream: Buffer | string): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#wrap + wrap(stream: Stream): void; } - - // Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/cursorstream.html - // Last update: doc. version 1.3.13 (29.08.2013) - export class CursorStream { - constructor(cursor: Cursor); - - public pause(): any; - public resume(): any; - public destroy(): any; - } - - export interface CollectionFindOptions { - limit?: number; - sort?: any; - fields?: Object; + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#count + export interface CursorCommentOptions { skip?: number; - hint?: Object; - explain?: boolean; - snapshot?: boolean; - timeout?: boolean; - tailtable?: boolean; - tailableRetryInterval?: number; - numberOfRetries?: number; - awaitdata?: boolean; - oplogReplay?: boolean; - exhaust?: boolean; - batchSize?: number; - returnKey?: boolean; - maxScan?: number; - min?: number; - max?: number; - showDiskLoc?: boolean; - comment?: String; - raw?: boolean; - readPreference?: String; - partial?: boolean; + limit?: number; + maxTimeMS?: number; + hint?: string; + readPreference?: ReadPreference | string; } - - export interface MongoCollectionOptions { - safe?: any; - serializeFunctions?: any; - strict?: boolean; - raw?: boolean; - pkFactory?: any; - readPreference?: string; + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#~iteratorCallback + export interface IteratorCallback { + (doc: any): void; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#~endCallback + export interface EndCallback { + (error: MongoError): void; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#~resultCallback + export type AggregationCursorResult = any | void; + + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html + export class AggregationCursor extends EventEmitter implements Readable { + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#batchSize + batchSize(value: number): AggregationCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#clone + clone(): AggregationCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#close + close(): Promise; + close(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#each + each(callback: MongoCallback): void + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#explain + explain(): Promise; + explain(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#geoNear + geoNear(document: Object): AggregationCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#group + group(document: Object): AggregationCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#isClosed + isClosed(): boolean; + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#limit + limit(value: number): AggregationCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#match + match(document: Object): AggregationCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#maxTimeMS + maxTimeMS(value: number): AggregationCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#next + next(): Promise; + next(callback: MongoCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#out + out(destination: string): AggregationCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#pause + pause(): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#pipe + pipe(destination: Writable, options?: Object): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#project + project(document: Object): AggregationCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#read + read(size: number): string | Buffer | void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#redact + redact(document: Object): AggregationCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#resume + resume(): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#rewind + rewind(): AggregationCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#setEncoding + setEncoding(encoding: string): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#skip + skip(value: number): AggregationCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#sort + sort(document: Object): AggregationCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#toArray + toArray(): Promise; + toArray(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#unpipe + unpipe(destination?: Writable): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#unshift + unshift(stream: Buffer | string): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#unwind + unwind(field: string): AggregationCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#wrap + wrap(stream: Stream): void; + } + + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html + export class CommandCursor extends EventEmitter implements Readable { + // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#batchSize + batchSize(value: number): CommandCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#clone + clone(): CommandCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#close + close(): Promise; + close(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#each + each(callback: MongoCallback): void + // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#isClosed + isClosed(): boolean; + // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#maxTimeMS + maxTimeMS(value: number): CommandCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#next + next(): Promise; + next(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#pause + pause(): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#pipe + pipe(destination: Writable, options?: Object): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#read + read(size: number): string | Buffer | void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#resume + resume(): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#rewind + rewind(): CommandCursor; + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#setEncoding + setEncoding(encoding: string): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#setReadPreference + setReadPreference(readPreference: string | ReadPreference): CommandCursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#toArray + toArray(): Promise; + toArray(callback: MongoCallback): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#unpipe + unpipe(destination?: Writable): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#unshift + unshift(stream: Buffer | string): void; + //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#wrap + wrap(stream: Stream): void; } }