@blueleader07/typeorm
Version:
Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.
1,367 lines (1,365 loc) • 195 kB
TypeScript
import { EventEmitter, Readable, Writable } from "../../platform/PlatformTools";
/**
* Creates a new MongoClient instance.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/MongoClient.html
*/
export declare class MongoClient extends EventEmitter {
constructor(uri: string, options?: MongoClientOptions);
/**
* Connect to MongoDB using a url as documented at docs.mongodb.org/manual/reference/connection-string/
* Note that for replicasets the replicaSet query parameter is required in the 2.0 driver.
*
* @param url The connection URI string.
* @param callback The command result callback.
*/
static connect(url: string, callback: MongoCallback<Db>): void;
/**
* Connect to MongoDB using a url as documented at docs.mongodb.org/manual/reference/connection-string/
* Note that for replicasets the replicaSet query parameter is required in the 2.0 driver.
*
* @param url The connection URI string.
* @param options Optional settings.
*/
static connect(url: string, options?: MongoClientOptions): Promise<Db>;
/**
* Connect to MongoDB using a url as documented at docs.mongodb.org/manual/reference/connection-string/
* Note that for replicasets the replicaSet query parameter is required in the 2.0 driver.
*
* @param url The connection URI string.
* @param options Optional settings.
* @param callback The command result callback.
*/
static connect(url: string, options: MongoClientOptions, callback: MongoCallback<Db>): void;
/**
* Connect to MongoDB using a url as documented at docs.mongodb.org/manual/reference/connection-string/
* Note that for replicasets the replicaSet query parameter is required in the 2.0 driver.
*/
connect(): Promise<MongoClient>;
/**
* Connect to MongoDB using a url as documented at docs.mongodb.org/manual/reference/connection-string/
* Note that for replicasets the replicaSet query parameter is required in the 2.0 driver.
*
* @param url The connection URI string.
* @param callback The command result callback.
*/
connect(url: string, callback: MongoCallback<Db>): void;
/**
* Connect to MongoDB using a url as documented at docs.mongodb.org/manual/reference/connection-string/
* Note that for replicasets the replicaSet query parameter is required in the 2.0 driver.
*
* @param url The connection URI string.
* @param options Optional settings.
*/
connect(url: string, options?: MongoClientOptions): Promise<Db>;
/**
* Connect to MongoDB using a url as documented at docs.mongodb.org/manual/reference/connection-string/
* Note that for replicasets the replicaSet query parameter is required in the 2.0 driver.
*
* @param url The connection URI string.
* @param options Optional settings.
* @param callback The command result callback.
*/
connect(url: string, options: MongoClientOptions, callback: MongoCallback<Db>): void;
/**
* Close the db and its underlying connections.
* @param callback The result callback.
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#close
*/
close(callback: MongoCallback<void>): void;
/**
* Close the db and its underlying connections.
* @param force Force close, emitting no events.
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#close
*/
close(force?: boolean): Promise<void>;
/**
* Close the db and its underlying connections.
* @param force Force close, emitting no events.
* @param callback The result callback.
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#close
*/
close(force: boolean, callback: MongoCallback<void>): void;
/**
* Create a new Db instance sharing the current socket connections. Be aware that the new db instances are
* related in a parent-child relationship to the original instance so that events are correctly emitted on child
* db instances. Child db instances are cached so performing db('db1') twice will return the same instance.
* You can control these behaviors with the options noListener and returnNonCachedInstance.
* @param dbName The name of the database we want to use. If not provided, use database name from connection string.
* @param options Optional settings.
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#db
*/
db(dbName?: string, options?: MongoClientCommonOption): Db;
/**
* Check if MongoClient is connected.
* @param options Optional settings.
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#isConnected
*/
isConnected(options?: MongoClientCommonOption): boolean;
/**
* Logout user from server, fire off on all connections and remove all auth info.
* @param callback The result callback.
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#logout
*/
logout(callback: MongoCallback<any>): void;
logout(options?: {
dbName?: string;
}): Promise<any>;
logout(options: {
dbName?: string;
}, callback: MongoCallback<any>): void;
/**
* Starts a new session on the server.
* @param options Optional settings.
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#startSession
*/
startSession(options?: SessionOptions): ClientSession;
/**
* Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this cluster.
* Will ignore all changes to system collections, as well as the local, admin, and config databases.
* @param pipeline An array of aggregation pipeline stages through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
* @param options Optional settings.
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#watch
*/
watch(pipeline?: Object[], options?: ChangeStreamOptions & {
startAtClusterTime?: Timestamp;
session?: ClientSession;
}): ChangeStream;
/**
* Runs a given operation with an implicitly created session. The lifetime of the session will be handled without the need for user interaction.
* @param operation An operation to execute with an implicitly created session. The signature of this MUST be `(session) => {}`
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#withSession
*/
withSession(operation: (session: ClientSession) => Promise<any>): Promise<void>;
/**
* Runs a given operation with an implicitly created session. The lifetime of the session will be handled without the need for user interaction.
* @param options Optional settings to be appled to implicitly created session.
* @param operation An operation to execute with an implicitly created session. The signature of this MUST be `(session) => {}`
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#withSession
*/
withSession(options: SessionOptions, operation: (session: ClientSession) => Promise<any>): Promise<void>;
}
/**
* The callback format for results.
*/
export interface MongoCallback<T> {
/**
* @param error An error instance representing the error during the execution.
* @param result The result of execution.
*/
(error: MongoError, result: T): void;
}
export declare class MongoError extends Error {
constructor(message: string);
static create(options: Object): MongoError;
}
/**
* Options for MongoClient#connect method.
*
* @see http://mongodb.github.io/node-mongodb-native/2.2/api/MongoClient.html#.connect
*/
export interface MongoClientOptions {
/**
* The maximum size of the individual server pool.
*/
poolSize?: number;
/**
* Enable SSL connection.
*/
ssl?: boolean;
/**
* SSL Certificate store binary buffer.
*/
sslCA?: Buffer;
/**
* Uri decode the user name and password for authentication.
*/
uri_decode_auth?: boolean;
/**
* A hash of options to set on the db object, see Db constructor.
*/
db?: DbCreateOptions;
/**
* A hash of options to set on the server objects, see Server constructor**.
*/
server?: ServerOptions;
/**
* A hash of options to set on the replSet object, see ReplSet constructor**.
*/
replSet?: ReplSetOptions;
/**
* A hash of options to set on the mongos object, see Mongos constructor**.
*/
mongos?: MongosOptions;
/**
* A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible.
*/
promiseLibrary?: Object;
}
export interface CommandOptions {
/**
* The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED,
* ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
*/
readPreference?: ReadPreference | string;
/**
* Number of milliseconds to wait before aborting the query.
*/
maxTimeMS?: number;
}
/**
* Options for Db class.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html
*/
export interface DbCreateOptions {
/**
* If the database authentication is dependent on another databaseName.
*/
authSource?: string;
/**
* The write concern.
*/
w?: number | string;
/**
* The write concern timeout.
*/
wtimeout?: number;
/**
* Specify a journal write concern.
*/
j?: boolean;
/**
* The current value of the parameter native_parser.
*/
native_parser?: boolean;
/**
* Force server to assign _id values instead of driver.
*/
forceServerObjectId?: boolean;
/**
* Serialize functions on any object.
*/
serializeFunctions?: boolean;
/**
* Specify if the BSON serializer should ignore undefined fields.
*/
ignoreUndefined?: boolean;
/**
* Return document results as raw BSON buffers.
*/
raw?: boolean;
/**
* Promotes Long values to number if they fit inside the 53 bits resolution.
*/
promoteLongs?: boolean;
/**
* Sets a cap on how many operations the driver will buffer up before giving up on getting a working connection, default is -1 which is unlimited.
*/
bufferMaxEntries?: number;
/**
* The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
*/
readPreference?: ReadPreference | string;
/**
* A primary key factory object for generation of custom _id keys.
*/
pkFactory?: Object;
/**
* A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible.
*/
promiseLibrary?: Object;
/**
* Specify a read concern for the collection. (only MongoDB 3.2 or higher supported).
*/
readConcern?: ReadConcern;
}
/**
* Creates a new ReadPreference instance.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/ReadPreference.html
*/
export declare class ReadPreference {
constructor(mode: string, tags: Object);
/**
* The ReadPreference mode as listed above.
*/
mode: string;
/**
* An object representing read preference tags.
*/
tags: any;
/**
* Read from primary only. All operations produce an error (throw an exception where applicable) if primary is unavailable. Cannot be combined with tags (This is the default.).
*/
static PRIMARY: string;
/**
* Read from primary if available, otherwise a secondary.
*/
static PRIMARY_PREFERRED: string;
/**
* Read from secondary if available, otherwise error.
*/
static SECONDARY: string;
/**
* Read from a secondary if available, otherwise read from the primary.
*/
static SECONDARY_PREFERRED: string;
/**
* All modes read from among the nearest candidates, but unlike other modes, NEAREST will include both the primary and all secondaries in the random selection.
*/
static NEAREST: string;
/**
* Validate if a mode is legal.
*/
isValid(mode: string): boolean;
/**
* Validate if a mode is legal.
*/
static isValid(mode: string): boolean;
}
/**
* Creates a new Server instance.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html
*/
export interface SocketOptions {
/**
* Reconnect on error.
*/
autoReconnect?: boolean;
/**
* TCP Socket NoDelay option.
*/
noDelay?: boolean;
/**
* TCP KeepAlive on the socket with a X ms delay before start.
*/
keepAlive?: number;
/**
* TCP Connection timeout setting.
*/
connectTimeoutMS?: number;
/**
* TCP Socket timeout setting.
*/
socketTimeoutMS?: number;
}
/**
* Creates a new Server instance.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html
*/
export interface ServerOptions {
/**
* Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons.
*/
poolSize?: number;
/**
* Use ssl connection (needs to have a mongod server with ssl support).
*/
ssl?: boolean;
/**
* Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslValidate?: Object;
/**
* Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function.
*/
checkServerIdentity?: boolean | Function;
/**
* Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslCA?: Array<Buffer | string>;
/**
* String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslCert?: Buffer | string;
/**
* String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslKey?: Buffer | string;
/**
* String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslPass?: Buffer | string;
/**
* Socket options.
*/
socketOptions?: SocketOptions;
/**
* Server attempt to reconnect #times.
*/
reconnectTries?: number;
/**
* Server will wait # milliseconds between retries.
*/
reconnectInterval?: number;
}
/**
* Creates a new ReplSet instance.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/ReplSet.html
*/
export interface ReplSetOptions {
/**
* Turn on high availability monitoring.
*/
ha?: boolean;
/**
* Time between each replicaset status check.
*/
haInterval?: number;
/**
* The name of the replicaset to connect to.
*/
replicaSet?: string;
/**
* Sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms).
*/
secondaryAcceptableLatencyMS?: number;
/**
* Sets if the driver should connect even if no primary is available.
*/
connectWithNoPrimary?: boolean;
/**
* Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons.
*/
poolSize?: number;
/**
* Use ssl connection (needs to have a mongod server with ssl support).
*/
ssl?: boolean;
/**
* Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslValidate?: Object;
/**
* Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function.
*/
checkServerIdentity?: boolean | Function;
/**
* Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslCA?: Array<Buffer | string>;
/**
* String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslCert?: Buffer | string;
/**
* String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslKey?: Buffer | string;
/**
* String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslPass?: Buffer | string;
/**
* Socket options.
*/
socketOptions?: SocketOptions;
}
/**
* Creates a new Mongos instance.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Mongos.html
*/
export interface MongosOptions {
/**
* Turn on high availability monitoring.
*/
ha?: boolean;
/**
* Time between each replicaset status check.
*/
haInterval?: number;
/**
* Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons.
*/
poolSize?: number;
/**
* Use ssl connection (needs to have a mongod server with ssl support).
*/
ssl?: boolean;
/**
* Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslValidate?: Object;
/**
* Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function.
*/
checkServerIdentity?: boolean | Function;
/**
* Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslCA?: Array<Buffer | string>;
/**
* String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslCert?: Buffer | string;
/**
* String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslKey?: Buffer | string;
/**
* String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher).
*/
sslPass?: Buffer | string;
/**
* Socket options.
*/
socketOptions?: SocketOptions;
}
export interface DbOptions {
/**
* Do not make the db an event listener to the original connection.
*/
noListener?: boolean;
/**
* Control if you want to return a cached instance or have a new one created.
*/
returnNonCachedInstance?: boolean;
}
export interface IndexInformationOptions {
/**
* Returns the full raw index information.
*/
full?: boolean;
/**
* The preferred read preference (ReadPreference.PRIMARY,
* ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY,
* ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
*/
readPreference?: ReadPreference | string;
}
export interface ExecuteDbAdminCommandOptions {
/**
* The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED,
* ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
*/
readPreference?: ReadPreference | string;
}
export interface ListCollectionsOptions {
/**
* The batchSize for the returned command cursor or if pre 2.8 the systems batch collection.
*/
batchSize?: number;
/**
* The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED,
* ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
*/
readPreference?: ReadPreference | string;
}
/**
* Db.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html
*/
export declare class Db extends EventEmitter {
/**
*
* @param databaseName The name of the database this instance represents.
* @param serverConfig The server topology for the database.
* @param options Optional.
*/
constructor(databaseName: string, serverConfig: Server | ReplSet | Mongos, options?: DbCreateOptions);
/**
* Get the current db topology.
*/
serverConfig: Server | ReplSet | Mongos;
/**
* Current bufferMaxEntries value for the database.
*/
bufferMaxEntries: number;
/**
* The name of the database this instance represents.
*/
databaseName: string;
/**
* The options associated with the db instance.
*/
options: any;
/**
* The current value of the parameter native_parser.
*/
native_parser: boolean;
/**
* The current slaveOk value for the db instance.
*/
slaveOk: boolean;
/**
* The current write concern values.
*/
writeConcern: WriteConcern;
/**
* Add a user to the database.
*
* @param username The username.
* @param password The password.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#addUser
*/
addUser(username: string, password: string, callback: MongoCallback<any>): void;
/**
* Add a user to the database.
*
* @param username The username.
* @param password The password.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#addUser
*/
addUser(username: string, password: string, options?: DbAddUserOptions): Promise<any>;
/**
* Add a user to the database.
*
* @param username The username.
* @param password The password.
* @param options Optional settings.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#addUser
*/
addUser(username: string, password: string, options: DbAddUserOptions, callback: MongoCallback<any>): void;
/**
* Return the Admin db instance.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#admin
*/
admin(): Admin;
/**
* Authenticate a user against the server.
*
* @param userName The username.
* @param password The password.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#authenticate
*/
authenticate(userName: string, password: string, callback: MongoCallback<any>): void;
/**
* Authenticate a user against the server.
*
* @param userName The username.
* @param password The password.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#authenticate
*/
authenticate(userName: string, password: string, options?: {
authMechanism: string;
}): Promise<any>;
/**
* Authenticate a user against the server.
*
* @param userName The username.
* @param password The password.
* @param password
* @param options
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#authenticate
*/
authenticate(userName: string, password: string, options: {
authMechanism: string;
}, callback: MongoCallback<any>): void;
/**
* Close the db and its underlying connections.
*
* @param callback The result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#close
*/
close(callback: MongoCallback<void>): void;
/**
* Close the db and its underlying connections.
*
* @param forceClose Force close, emitting no events.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#close
*/
close(forceClose?: boolean): Promise<void>;
/**
* Close the db and its underlying connections.
*
* @param forceClose Force close, emitting no events.
* @param callback The result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#close
*/
close(forceClose: boolean, callback: MongoCallback<void>): void;
/**
* Fetch a specific collection (containing the actual collection information). If the application does not use strict mode you can
* can use it without a callback in the following way: var collection = db.collection('mycollection');
*
* @param name The collection name we wish to access.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#collection
*/
collection(name: string): Collection<any>;
/**
* Fetch a specific collection (containing the actual collection information). If the application does not use strict mode you can
* can use it without a callback in the following way: var collection = db.collection('mycollection');
*
* @param name The collection name we wish to access.
* @param callback The collection result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#collection
*/
collection(name: string, callback: MongoCallback<Collection<any>>): Collection<any>;
/**
* Fetch a specific collection (containing the actual collection information). If the application does not use strict mode you can
* can use it without a callback in the following way: var collection = db.collection('mycollection');
*
* @param name The collection name we wish to access.
* @param options Optional settings.
* @param callback The collection result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#collection
*/
collection(name: string, options: DbCollectionOptions, callback: MongoCallback<Collection<any>>): Collection<any>;
/**
* Fetch all collections for the current db.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#collections
*/
collections(): Promise<Collection<any>[]>;
/**
* Fetch all collections for the current db.
*
* @param callback The results callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#collections
*/
collections(callback: MongoCallback<Collection<any>[]>): void;
/**
* Execute a command.
*
* @param command The command hash.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#command
*/
command(command: Object, callback: MongoCallback<any>): void;
/**
* Execute a command.
*
* @param command The command hash.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#command
*/
command(command: Object, options?: {
readPreference: ReadPreference | string;
}): Promise<any>;
/**
* Execute a command.
*
* @param command The command hash.
* @param options Optional settings.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#command
*/
command(command: Object, options: {
readPreference: ReadPreference | string;
}, callback: MongoCallback<any>): void;
/**
* Create a new collection on a server with the specified options. Use this to create capped collections.
*
* @param name The collection name we wish to access.
* @param callback The results callback
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createCollection
*/
createCollection(name: string, callback: MongoCallback<Collection<any>>): void;
/**
* Create a new collection on a server with the specified options. Use this to create capped collections.
*
* @param name The collection name we wish to access.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createCollection
*/
createCollection(name: string, options?: CollectionCreateOptions): Promise<Collection<any>>;
/**
* Create a new collection on a server with the specified options. Use this to create capped collections.
*
* @param name The collection name we wish to access.
* @param options Optional settings.
* @param callback The results callback
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createCollection
*/
createCollection(name: string, options: CollectionCreateOptions, callback: MongoCallback<Collection<any>>): void;
/**
* Creates an index on the db and collection collection.
*
* @param name Name of the collection to create the index on.
* @param fieldOrSpec Defines the index.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createIndex
*/
createIndex(name: string, fieldOrSpec: string | Object, callback: MongoCallback<any>): void;
/**
* Creates an index on the db and collection collection.
*
* @param name Name of the collection to create the index on.
* @param fieldOrSpec Defines the index.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createIndex
*/
createIndex(name: string, fieldOrSpec: string | Object, options?: MongodbIndexOptions): Promise<any>;
/**
* Creates an index on the db and collection collection.
*
* @param name Name of the collection to create the index on.
* @param fieldOrSpec Defines the index.
* @param options Optional settings.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createIndex
*/
createIndex(name: string, fieldOrSpec: string | Object, options: MongodbIndexOptions, callback: MongoCallback<any>): void;
/**
* Create a new Db instance sharing the current socket connections. Be aware that the new db instances are
* related in a parent-child relationship to the original instance so that events are correctly emitted on child
* db instances. Child db instances are cached so performing db('db1') twice will return the same instance.
* You can control these behaviors with the options noListener and returnNonCachedInstance.
*
* @param dbName The name of the database we want to use.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#db
*/
db(dbName: string): Db;
/**
* Create a new Db instance sharing the current socket connections. Be aware that the new db instances are
* related in a parent-child relationship to the original instance so that events are correctly emitted on child
* db instances. Child db instances are cached so performing db('db1') twice will return the same instance.
* You can control these behaviors with the options noListener and returnNonCachedInstance.
*
* @param dbName The name of the database we want to use.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#db
*/
db(dbName: string, options: DbOptions): Db;
/**
* Drop a collection from the database, removing it permanently. New accesses will create a new collection.
*
* @param name Name of collection to drop.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#dropCollection
*/
dropCollection(name: string): Promise<boolean>;
/**
* Drop a collection from the database, removing it permanently. New accesses will create a new collection.
*
* @param name Name of collection to drop.
* @param callback The results callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#dropCollection
*/
dropCollection(name: string, callback: MongoCallback<boolean>): void;
/**
* Drop a database, removing it permanently from the server.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#dropDatabase
*/
dropDatabase(): Promise<any>;
/**
* Drop a database, removing it permanently from the server.
*
* @param callback The results callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#dropDatabase
*/
dropDatabase(callback: MongoCallback<any>): void;
/**
* Runs a command on the database as admin.
*
* @param command The command hash.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#executeDbAdminCommand
*/
executeDbAdminCommand(command: Object, callback: MongoCallback<any>): void;
/**
* Runs a command on the database as admin.
*
* @param command The command hash.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#executeDbAdminCommand
*/
executeDbAdminCommand(command: Object, options?: ExecuteDbAdminCommandOptions): Promise<any>;
/**
* Runs a command on the database as admin.
*
* @param command The command hash.
* @param options Optional settings.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#executeDbAdminCommand
*/
executeDbAdminCommand(command: Object, options: ExecuteDbAdminCommandOptions, callback: MongoCallback<any>): void;
/**
* Retrieves this collections index info.
*
* @param name The name of the collection.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#indexInformation
*/
indexInformation(name: string, callback: MongoCallback<any>): void;
/**
* Retrieves this collections index info.
*
* @param name The name of the collection.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#indexInformation
*/
indexInformation(name: string, options?: IndexInformationOptions): Promise<any>;
/**
* Retrieves this collections index info.
*
* @param name The name of the collection.
* @param options Optional settings.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#indexInformation
*/
indexInformation(name: string, options: IndexInformationOptions, callback: MongoCallback<any>): void;
/**
* Get the list of all collection information for the specified db.
*
* @param filter Query to filter collections by.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#listCollections
*/
listCollections(filter: Object, options?: ListCollectionsOptions): CommandCursor;
/**
* Logout user from server, fire off on all connections and remove all auth info.
*
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#logout
*/
logout(callback: MongoCallback<any>): void;
/**
* Logout user from server, fire off on all connections and remove all auth info.
*
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#logout
*/
logout(options?: {
dbName?: string;
}): Promise<any>;
/**
* Logout user from server, fire off on all connections and remove all auth info.
*
* @param options Optional settings.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#logout
*/
logout(options: {
dbName?: string;
}, callback: MongoCallback<any>): void;
/**
* Open the database.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#open
*/
open(): Promise<Db>;
/**
* Open the database
*
* @param callback Callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#open
*/
open(callback: MongoCallback<Db>): void;
/**
*
* @param username
* @param callback
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#removeUser
*/
removeUser(username: string, callback: MongoCallback<any>): void;
removeUser(username: string, options?: {
w?: number | string;
wtimeout?: number;
j?: boolean;
}): Promise<any>;
removeUser(username: string, options: {
w?: number | string;
wtimeout?: number;
j?: boolean;
}, callback: MongoCallback<any>): void;
/**
* Rename a collection.
*
* @param fromCollection Name of current collection to rename.
* @param toCollection New name of of the collection.
* @param callback The results callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#renameCollection
*/
renameCollection(fromCollection: string, toCollection: string, callback: MongoCallback<Collection<any>>): void;
/**
* Rename a collection.
*
* @param fromCollection Name of current collection to rename.
* @param toCollection New name of of the collection.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#renameCollection
*/
renameCollection(fromCollection: string, toCollection: string, options?: {
dropTarget?: boolean;
}): Promise<Collection<any>>;
/**
* Rename a collection.
*
* @param fromCollection Name of current collection to rename.
* @param toCollection New name of of the collection.
* @param options Optional settings.
* @param callback The results callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#renameCollection
*/
renameCollection(fromCollection: string, toCollection: string, options: {
dropTarget?: boolean;
}, callback: MongoCallback<Collection<any>>): void;
/**
* Get all the db statistics.
*
* @param callback The collection result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#stats
*/
stats(callback: MongoCallback<any>): void;
/**
* Get all the db statistics.
*
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#stats
*/
stats(options?: {
scale?: number;
}): Promise<any>;
/**
* Get all the db statistics.
*
* @param options Optional settings.
* @param callback The collection result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#stats
*/
stats(options: {
scale?: number;
}, callback: MongoCallback<any>): void;
/**
* Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this database. Will ignore all changes to system collections.
* @param pipeline An array of aggregation pipeline stages through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
* @param options Optional settings.
* @see http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#watch
*/
watch(pipeline?: Object[], options?: ChangeStreamOptions & {
startAtClusterTime?: Timestamp;
session?: ClientSession;
}): ChangeStream;
}
/**
* Server.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html
*/
export declare class Server extends EventEmitter {
/**
*
* @param host The host for the server, can be either an IP4, IP6 or domain socket style host.
* @param port The server port if IP4.
* @param options Optional.
*/
constructor(host: string, port: number, options?: ServerOptions);
/**
* All raw connections.
*/
connections(): Array<any>;
}
/**
* ReplSet.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/ReplSet.html
*/
export declare class ReplSet extends EventEmitter {
/**
*
* @param servers A seedlist of servers participating in the replicaset.
* @param options Optional.
*/
constructor(servers: Array<Server>, options?: ReplSetOptions);
/**
* All raw connections
*/
connections(): Array<any>;
}
/**
* Mongos.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Mongos.html
*/
export declare class Mongos extends EventEmitter {
/**
*
* @param servers A seedlist of servers participating in the replicaset.
* @param options Optional.
*/
constructor(servers: Array<Server>, options?: MongosOptions);
/**
* All raw connections
*/
connections(): Array<any>;
}
/**
* Creates a new Db instance.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#addUser
*/
export interface DbAddUserOptions {
/**
* The write concern.
*/
w?: string | number;
/**
* The write concern timeout.
*/
wtimeout?: number;
/**
* Specify a journal write concern.
*/
j?: boolean;
/**
* Custom data associated with the user (only Mongodb 2.6 or higher).
*/
customData?: Object;
/**
* Roles associated with the created user (only Mongodb 2.6 or higher).
*/
roles?: Object[];
}
/**
* Creates a new Db instance.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createCollection
*/
export interface CollectionCreateOptions {
/**
* The write concern.
*/
w?: number | string;
/**
* The write concern timeout.
*/
wtimeout?: number;
/**
* Specify a journal write concern.
*/
j?: boolean;
/**
* Return document results as raw BSON buffers.
*/
raw?: boolean;
/**
* A primary key factory object for generation of custom _id keys.
*/
pkFactory?: Object;
/**
* The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
*/
readPreference?: ReadPreference | string;
/**
* Serialize functions on any object.
*/
serializeFunctions?: boolean;
/**
* Returns an error if the collection does not exist.
*/
strict?: boolean;
/**
* Create a capped collection.
*/
capped?: boolean;
/**
* The size of the capped collection in bytes.
*/
size?: number;
/**
* The maximum number of documents in the capped collection.
*/
max?: number;
/**
* Create an index on the _id field of the document, True by default on MongoDB 2.2 or higher off for version < 2.2.
*/
autoIndexId?: boolean;
}
/**
* Creates a new Db instance.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#collection
*/
export interface DbCollectionOptions {
/**
* The write concern.
*/
w?: number | string;
/**
* The write concern timeout.
*/
wtimeout?: number;
/**
* Specify a journal write concern.
*/
j?: boolean;
/**
* Return document results as raw BSON buffers.
*/
raw?: boolean;
/**
* A primary key factory object for generation of custom _id keys.
*/
pkFactory?: Object;
/**
* The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
*/
readPreference?: ReadPreference | string;
/**
* Serialize functions on any object.
*/
serializeFunctions?: boolean;
/**
* Returns an error if the collection does not exist.
*/
strict?: boolean;
/**
* Specify a read concern for the collection. (only MongoDB 3.2 or higher supported).
*/
readConcern?: ReadConcern;
}
/**
* Creates an index on the db and collection collection.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html#createIndex
*/
export interface MongodbIndexOptions {
/**
* 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 geospatial indexes set the lower bound for the co-ordinates.
*/
min?: number;
/**
* For geospatial 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 autogenerated index name (useful if the resulting name is larger than 128 bytes).
*/
name?: string;
}
/**
* Admin.
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html
*/
export interface Admin {
/**
* Add a user to the database.
*
* @param username The username.
* @param password The password.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#addUser
*/
addUser(username: string, password: string, callback: MongoCallback<any>): void;
/**
* Add a user to the database.
*
* @param username The username.
* @param password The password.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#addUser
*/
addUser(username: string, password: string, options?: AddUserOptions): Promise<any>;
/**
* Add a user to the database.
*
* @param username The username.
* @param password The password.
* @param options Optional settings.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#addUser
*/
addUser(username: string, password: string, options: AddUserOptions, callback: MongoCallback<any>): void;
/**
* Authenticate a user against the server.
*
* @param username The username.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#authenticate
*/
authenticate(username: string, callback: MongoCallback<any>): void;
/**
* Authenticate a user against the server.
*
* @param username The username.
* @param password The password.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#authenticate
*/
authenticate(username: string, password?: string): Promise<any>;
/**
* Authenticate a user against the server.
*
* @param username The username.
* @param password The password.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#authenticate
*/
authenticate(username: string, password: string, callback: MongoCallback<any>): void;
/**
* Retrieve the server information for the current instance of the db client
*
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#buildInfo
*/
buildInfo(): Promise<any>;
/**
* Retrieve the server information for the current instance of the db client
*
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#buildInfo
*/
buildInfo(callback: MongoCallback<any>): void;
/**
* Execute a command.
*
* @param command The command hash.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#command
*/
command(command: Object, callback: MongoCallback<any>): void;
/**
* Execute a command.
*
* @param command The command hash.
* @param options Optional.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#command
*/
command(command: Object, options?: CommandOptions): Promise<any>;
/**
* Execute a command.
*
* @param command The command hash.
* @param options Optional settings.
* @param callback The command result callback.
* @see http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#command
*/