diff --git a/src/admin.ts b/src/admin.ts index 61d67dbc509..0884932ff6e 100644 --- a/src/admin.ts +++ b/src/admin.ts @@ -1,6 +1,5 @@ import type { Document } from './bson'; import type { Db } from './db'; -import { AddUserOperation, type AddUserOptions } from './operations/add_user'; import type { CommandOperationOptions } from './operations/command'; import { executeOperation } from './operations/execute_operation'; import { @@ -116,33 +115,6 @@ export class Admin { return this.command({ ping: 1 }, options); } - /** - * Add a user to the database - * - * @param username - The username for the new user - * @param passwordOrOptions - An optional password for the new user, or the options for the command - * @param options - Optional settings for the command - * @deprecated Use the createUser command in `db.command()` instead. - * @see https://www.mongodb.com/docs/manual/reference/command/createUser/ - */ - async addUser( - username: string, - passwordOrOptions?: string | AddUserOptions, - options?: AddUserOptions - ): Promise { - options = - options != null && typeof options === 'object' - ? options - : passwordOrOptions != null && typeof passwordOrOptions === 'object' - ? passwordOrOptions - : undefined; - const password = typeof passwordOrOptions === 'string' ? passwordOrOptions : undefined; - return executeOperation( - this.s.db.client, - new AddUserOperation(this.s.db, username, password, { dbName: 'admin', ...options }) - ); - } - /** * Remove a user from a database * diff --git a/src/collection.ts b/src/collection.ts index 941618f4e73..6b4a97031c9 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -80,7 +80,6 @@ import { } from './operations/search_indexes/create'; import { DropSearchIndexOperation } from './operations/search_indexes/drop'; import { UpdateSearchIndexOperation } from './operations/search_indexes/update'; -import { type CollStats, CollStatsOperation, type CollStatsOptions } from './operations/stats'; import { ReplaceOneOperation, type ReplaceOptions, @@ -799,21 +798,6 @@ export class Collection { ); } - /** - * Get all the collection statistics. - * - * @deprecated the `collStats` operation will be removed in the next major release. Please - * use an aggregation pipeline with the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/) stage instead - * - * @param options - Optional settings for the command - */ - async stats(options?: CollStatsOptions): Promise { - return executeOperation( - this.client, - new CollStatsOperation(this as TODO_NODE_3286, options) as TODO_NODE_3286 - ); - } - /** * Find a document and delete it in one atomic operation. Requires a write lock for the duration of the operation. * diff --git a/src/db.ts b/src/db.ts index 4b3c2d22f50..2a233f2ce1f 100644 --- a/src/db.ts +++ b/src/db.ts @@ -9,7 +9,6 @@ import { RunCommandCursor, type RunCursorCommandOptions } from './cursor/run_com import { MongoAPIError, MongoInvalidArgumentError } from './error'; import type { MongoClient, PkFactory } from './mongo_client'; import type { TODO_NODE_3286 } from './mongo_types'; -import { AddUserOperation, type AddUserOptions } from './operations/add_user'; import type { AggregateOptions } from './operations/aggregate'; import { CollectionsOperation } from './operations/collections'; import type { IndexInformationOptions } from './operations/common_functions'; @@ -418,33 +417,6 @@ export class Db { ); } - /** - * Add a user to the database - * - * @param username - The username for the new user - * @param passwordOrOptions - An optional password for the new user, or the options for the command - * @param options - Optional settings for the command - * @deprecated Use the createUser command in `db.command()` instead. - * @see https://www.mongodb.com/docs/manual/reference/command/createUser/ - */ - async addUser( - username: string, - passwordOrOptions?: string | AddUserOptions, - options?: AddUserOptions - ): Promise { - options = - options != null && typeof options === 'object' - ? options - : passwordOrOptions != null && typeof passwordOrOptions === 'object' - ? passwordOrOptions - : undefined; - const password = typeof passwordOrOptions === 'string' ? passwordOrOptions : undefined; - return executeOperation( - this.client, - new AddUserOperation(this, username, password, resolveOptions(this, options)) - ); - } - /** * Remove a user from a database * diff --git a/src/index.ts b/src/index.ts index 26282013f3f..9e94d18dca7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -378,7 +378,6 @@ export type { WithId, WithoutId } from './mongo_types'; -export type { AddUserOptions, RoleSpecification } from './operations/add_user'; export type { AggregateOperation, AggregateOptions, @@ -434,12 +433,7 @@ export type { RenameOptions } from './operations/rename'; export type { RunCommandOptions } from './operations/run_command'; export type { SearchIndexDescription } from './operations/search_indexes/create'; export type { SetProfilingLevelOptions } from './operations/set_profiling_level'; -export type { - CollStats, - CollStatsOptions, - DbStatsOptions, - WiredTigerData -} from './operations/stats'; +export type { DbStatsOptions } from './operations/stats'; export type { ReplaceOptions, UpdateOptions, diff --git a/src/operations/add_user.ts b/src/operations/add_user.ts deleted file mode 100644 index 40268e241c9..00000000000 --- a/src/operations/add_user.ts +++ /dev/null @@ -1,117 +0,0 @@ -import * as crypto from 'crypto'; - -import type { Document } from '../bson'; -import type { Db } from '../db'; -import { MongoInvalidArgumentError } from '../error'; -import type { Server } from '../sdam/server'; -import type { ClientSession } from '../sessions'; -import { type Callback, emitWarningOnce, getTopology } from '../utils'; -import { CommandOperation, type CommandOperationOptions } from './command'; -import { Aspect, defineAspects } from './operation'; - -/** - * @public - * @deprecated Use the createUser command directly instead. - */ -export interface RoleSpecification { - /** - * A role grants privileges to perform sets of actions on defined resources. - * A given role applies to the database on which it is defined and can grant access down to a collection level of granularity. - */ - role: string; - /** The database this user's role should effect. */ - db: string; -} - -/** - * @public - * @deprecated Use the createUser command directly instead. - */ -export interface AddUserOptions extends CommandOperationOptions { - /** Roles associated with the created user */ - roles?: string | string[] | RoleSpecification | RoleSpecification[]; - /** Custom data associated with the user (only Mongodb 2.6 or higher) */ - customData?: Document; -} - -/** @internal */ -export class AddUserOperation extends CommandOperation { - override options: AddUserOptions; - db: Db; - username: string; - password?: string; - - constructor(db: Db, username: string, password: string | undefined, options?: AddUserOptions) { - super(db, options); - - this.db = db; - this.username = username; - this.password = password; - this.options = options ?? {}; - } - - override execute(server: Server, session: ClientSession | undefined): Promise { - const db = this.db; - const username = this.username; - const password = this.password; - const options = this.options; - - // Error out if digestPassword set - // v5 removed the digestPassword option from AddUserOptions but we still want to throw - // an error when digestPassword is provided. - if ('digestPassword' in options && options.digestPassword != null) { - throw new MongoInvalidArgumentError( - 'Option "digestPassword" not supported via addUser, use db.command(...) instead' - ); - } - - let roles; - if (!options.roles || (Array.isArray(options.roles) && options.roles.length === 0)) { - emitWarningOnce( - 'Creating a user without roles is deprecated. Defaults to "root" if db is "admin" or "dbOwner" otherwise' - ); - if (db.databaseName.toLowerCase() === 'admin') { - roles = ['root']; - } else { - roles = ['dbOwner']; - } - } else { - roles = Array.isArray(options.roles) ? options.roles : [options.roles]; - } - - const topology = getTopology(db); - - const digestPassword = topology.lastHello().maxWireVersion >= 7; - - let userPassword = password; - - if (!digestPassword) { - // Use node md5 generator - const md5 = crypto.createHash('md5'); - // Generate keys used for authentication - md5.update(`${username}:mongo:${password}`); - userPassword = md5.digest('hex'); - } - - // Build the command to execute - const command: Document = { - createUser: username, - customData: options.customData || {}, - roles: roles, - digestPassword - }; - - // No password - if (typeof password === 'string') { - command.pwd = userPassword; - } - - return super.executeCommand(server, session, command); - } - - executeCallback(_server: Server, _session: ClientSession | undefined, _callback: Callback): void { - throw new Error('Method not implemented'); - } -} - -defineAspects(AddUserOperation, [Aspect.WRITE_OPERATION]); diff --git a/src/operations/stats.ts b/src/operations/stats.ts index bb73d447d6e..d538460582f 100644 --- a/src/operations/stats.ts +++ b/src/operations/stats.ts @@ -1,60 +1,11 @@ import type { Document } from '../bson'; -import type { Collection } from '../collection'; import type { Db } from '../db'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; import type { Callback } from '../utils'; -import { - CommandCallbackOperation, - CommandOperation, - type CommandOperationOptions -} from './command'; +import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; -/** - * @public - * @deprecated the `collStats` operation will be removed in the next major release. Please - * use an aggregation pipeline with the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/) stage instead - */ -export interface CollStatsOptions extends CommandOperationOptions { - /** Divide the returned sizes by scale value. */ - scale?: number; -} - -/** - * Get all the collection statistics. - * @internal - */ -export class CollStatsOperation extends CommandCallbackOperation { - override options: CollStatsOptions; - collectionName: string; - - /** - * Construct a Stats operation. - * - * @param collection - Collection instance - * @param options - Optional settings. See Collection.prototype.stats for a list of options. - */ - constructor(collection: Collection, options?: CollStatsOptions) { - super(collection, options); - this.options = options ?? {}; - this.collectionName = collection.collectionName; - } - - override executeCallback( - server: Server, - session: ClientSession | undefined, - callback: Callback - ): void { - const command: Document = { collStats: this.collectionName }; - if (this.options.scale != null) { - command.scale = this.options.scale; - } - - super.executeCommandCallback(server, session, command, callback); - } -} - /** @public */ export interface DbStatsOptions extends CommandOperationOptions { /** Divide the returned sizes by scale value. */ @@ -88,201 +39,4 @@ export class DbStatsOperation extends CommandOperation { } } -/** - * @deprecated the `collStats` operation will be removed in the next major release. Please - * use an aggregation pipeline with the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/) stage instead - * @public - * @see https://www.mongodb.com/docs/manual/reference/command/collStats/ - */ -export interface CollStats extends Document { - /** 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; - /** A number that indicates the user-set flags on the collection. userFlags only appears when using the mmapv1 storage engine */ - userFlags?: number; - /** Total index size in bytes */ - totalIndexSize: number; - /** Size of specific indexes in bytes */ - indexSizes: { - _id_: number; - [index: string]: number; - }; - /** `true` if the collection is capped */ - capped: boolean; - /** The maximum number of documents that may be present in a capped collection */ - max: number; - /** The maximum size of a capped collection */ - maxSize: number; - /** This document contains data reported directly by the WiredTiger engine and other data for internal diagnostic use */ - wiredTiger?: WiredTigerData; - /** The fields in this document are the names of the indexes, while the values themselves are documents that contain statistics for the index provided by the storage engine */ - indexDetails?: any; - ok: number; - - /** The amount of storage available for reuse. The scale argument affects this value. */ - freeStorageSize?: number; - /** An array that contains the names of the indexes that are currently being built on the collection */ - indexBuilds?: number; - /** The sum of the storageSize and totalIndexSize. The scale argument affects this value */ - totalSize: number; - /** The scale value used by the command. */ - scaleFactor: number; -} - -/** - * @public - * @deprecated This type is only used for the deprecated `collStats` operation and will be removed in the next major release. - */ -export interface WiredTigerData extends Document { - LSM: { - 'bloom filter false positives': number; - 'bloom filter hits': number; - 'bloom filter misses': number; - 'bloom filter pages evicted from cache': number; - 'bloom filter pages read into cache': number; - 'bloom filters in the LSM tree': number; - 'chunks in the LSM tree': number; - 'highest merge generation in the LSM tree': number; - 'queries that could have benefited from a Bloom filter that did not exist': number; - 'sleep for LSM checkpoint throttle': number; - 'sleep for LSM merge throttle': number; - 'total size of bloom filters': number; - } & Document; - 'block-manager': { - 'allocations requiring file extension': number; - 'blocks allocated': number; - 'blocks freed': number; - 'checkpoint size': number; - 'file allocation unit size': number; - 'file bytes available for reuse': number; - 'file magic number': number; - 'file major version number': number; - 'file size in bytes': number; - 'minor version number': number; - }; - btree: { - 'btree checkpoint generation': number; - 'column-store fixed-size leaf pages': number; - 'column-store internal pages': number; - 'column-store variable-size RLE encoded values': number; - 'column-store variable-size deleted values': number; - 'column-store variable-size leaf pages': number; - 'fixed-record size': number; - 'maximum internal page key size': number; - 'maximum internal page size': number; - 'maximum leaf page key size': number; - 'maximum leaf page size': number; - 'maximum leaf page value size': number; - 'maximum tree depth': number; - 'number of key/value pairs': number; - 'overflow pages': number; - 'pages rewritten by compaction': number; - 'row-store internal pages': number; - 'row-store leaf pages': number; - } & Document; - cache: { - 'bytes currently in the cache': number; - 'bytes read into cache': number; - 'bytes written from cache': number; - 'checkpoint blocked page eviction': number; - 'data source pages selected for eviction unable to be evicted': number; - 'hazard pointer blocked page eviction': number; - 'in-memory page passed criteria to be split': number; - 'in-memory page splits': number; - 'internal pages evicted': number; - 'internal pages split during eviction': number; - 'leaf pages split during eviction': number; - 'modified pages evicted': number; - 'overflow pages read into cache': number; - 'overflow values cached in memory': number; - 'page split during eviction deepened the tree': number; - 'page written requiring lookaside records': number; - 'pages read into cache': number; - 'pages read into cache requiring lookaside entries': number; - 'pages requested from the cache': number; - 'pages written from cache': number; - 'pages written requiring in-memory restoration': number; - 'tracked dirty bytes in the cache': number; - 'unmodified pages evicted': number; - } & Document; - cache_walk: { - 'Average difference between current eviction generation when the page was last considered': number; - 'Average on-disk page image size seen': number; - 'Clean pages currently in cache': number; - 'Current eviction generation': number; - 'Dirty pages currently in cache': number; - 'Entries in the root page': number; - 'Internal pages currently in cache': number; - 'Leaf pages currently in cache': number; - 'Maximum difference between current eviction generation when the page was last considered': number; - 'Maximum page size seen': number; - 'Minimum on-disk page image size seen': number; - 'On-disk page image sizes smaller than a single allocation unit': number; - 'Pages created in memory and never written': number; - 'Pages currently queued for eviction': number; - 'Pages that could not be queued for eviction': number; - 'Refs skipped during cache traversal': number; - 'Size of the root page': number; - 'Total number of pages currently in cache': number; - } & Document; - compression: { - 'compressed pages read': number; - 'compressed pages written': number; - 'page written failed to compress': number; - 'page written was too small to compress': number; - 'raw compression call failed, additional data available': number; - 'raw compression call failed, no additional data available': number; - 'raw compression call succeeded': number; - } & Document; - cursor: { - 'bulk-loaded cursor-insert calls': number; - 'create calls': number; - 'cursor-insert key and value bytes inserted': number; - 'cursor-remove key bytes removed': number; - 'cursor-update value bytes updated': number; - 'insert calls': number; - 'next calls': number; - 'prev calls': number; - 'remove calls': number; - 'reset calls': number; - 'restarted searches': number; - 'search calls': number; - 'search near calls': number; - 'truncate calls': number; - 'update calls': number; - }; - reconciliation: { - 'dictionary matches': number; - 'fast-path pages deleted': number; - 'internal page key bytes discarded using suffix compression': number; - 'internal page multi-block writes': number; - 'internal-page overflow keys': number; - 'leaf page key bytes discarded using prefix compression': number; - 'leaf page multi-block writes': number; - 'leaf-page overflow keys': number; - 'maximum blocks required for a page': number; - 'overflow values written': number; - 'page checksum matches': number; - 'page reconciliation calls': number; - 'page reconciliation calls for eviction': number; - 'pages deleted': number; - } & Document; -} - -defineAspects(CollStatsOperation, [Aspect.READ_OPERATION]); defineAspects(DbStatsOperation, [Aspect.READ_OPERATION]); diff --git a/test/integration/connection-monitoring-and-pooling/connection.test.ts b/test/integration/connection-monitoring-and-pooling/connection.test.ts index 731a1415502..3d8ac02e3be 100644 --- a/test/integration/connection-monitoring-and-pooling/connection.test.ts +++ b/test/integration/connection-monitoring-and-pooling/connection.test.ts @@ -295,11 +295,7 @@ describe('Connection', function () { // First add a user. const db = client.db(configuration.db); - - db.addUser(username, password, function (err) { - expect(err).to.not.exist; - restOfTest(); - }); + db.command({ createUser: username, pwd: password }).then(restOfTest, done); function restOfTest() { testClient = configuration.newClient(configuration.url({ username, password })); @@ -324,10 +320,10 @@ describe('Connection', function () { client = configuration.newClient(); const db = client.db(configuration.db); - db.addUser(username, password, { roles: ['readWrite', 'dbAdmin'] }, function (err) { - expect(err).to.not.exist; - restOfTest(); - }); + db.command({ createUser: username, pwd: password, roles: ['readWrite', 'dbAdmin'] }).then( + restOfTest, + done + ); function restOfTest() { const opts = { auth: { username, password }, authSource: configuration.db }; diff --git a/test/integration/enumerate_databases.test.ts b/test/integration/enumerate_databases.test.ts index decb0ac892c..0f7f03db9a0 100644 --- a/test/integration/enumerate_databases.test.ts +++ b/test/integration/enumerate_databases.test.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import { once } from 'events'; -import { type AddUserOptions, type MongoClient, MongoServerError } from '../mongodb'; +import { type MongoClient, MongoServerError } from '../mongodb'; import { TestBuilder, UnifiedTestSuiteBuilder } from '../tools/utils'; const metadata: MongoDBMetadataUI = { @@ -25,10 +25,6 @@ describe('listDatabases()', function () { let adminClient: MongoClient; let authorizedClient: MongoClient; - const authorizedUserOptions: AddUserOptions = { - roles: [{ role: 'read', db: mockAuthorizedDb }] - }; - beforeEach(async function () { adminClient = this.configuration.newClient(); @@ -37,7 +33,11 @@ describe('listDatabases()', function () { .createCollection(mockAuthorizedCollection) .catch(() => null); - await adminClient.db('admin').addUser(username, password, authorizedUserOptions); + await adminClient.db('admin').command({ + createUser: username, + pwd: password, + roles: [{ role: 'read', db: mockAuthorizedDb }] + }); authorizedClient = this.configuration.newClient({ auth: { username: username, password: password } @@ -189,6 +189,7 @@ describe('listDatabases()', function () { }); } }); + UnifiedTestSuiteBuilder.describe('comment option') .createEntities(UnifiedTestSuiteBuilder.defaultEntities) .initialData({ diff --git a/test/integration/node-specific/auto_connect.test.ts b/test/integration/node-specific/auto_connect.test.ts index 73823beb7e5..926ed574a46 100644 --- a/test/integration/node-specific/auto_connect.test.ts +++ b/test/integration/node-specific/auto_connect.test.ts @@ -36,14 +36,6 @@ describe('When executing an operation for the first time', () => { }); describe(`class Admin`, () => { - describe(`#addUser()`, () => { - it('should connect the client', async () => { - const admin = client.db().admin(); - await admin.addUser('neal', 'iLoveJavaScript', { roles: ['root'] }).catch(() => null); - expect(client).to.have.property('topology').that.is.instanceOf(Topology); - }); - }); - describe(`#buildInfo()`, () => { it('should connect the client', async () => { const admin = client.db().admin(); @@ -557,14 +549,6 @@ describe('When executing an operation for the first time', () => { }); describe(`class Db`, () => { - describe(`#addUser()`, () => { - it('should connect the client', async () => { - const db = client.db(); - await db.addUser('neal', 'iLoveJavaScript', { roles: ['dbAdmin'] }).catch(() => null); - expect(client).to.have.property('topology').that.is.instanceOf(Topology); - }); - }); - describe(`#collections()`, () => { it('should connect the client', async () => { const db = client.db(); diff --git a/test/integration/node-specific/operation_examples.test.ts b/test/integration/node-specific/operation_examples.test.ts index 3e2f7c1f0b0..3c9dd2676d9 100644 --- a/test/integration/node-specific/operation_examples.test.ts +++ b/test/integration/node-specific/operation_examples.test.ts @@ -2209,118 +2209,6 @@ describe('Operations', function () { } }); - /** - * An example of adding a user to the database using a Promise. - * - * example-class Db - * example-method addUser - */ - it('shouldCorrectlyAddUserToDbWithPromises', { - metadata: { requires: { topology: 'single' } }, - - test: function () { - const configuration = this.configuration; - const client = configuration.newClient(configuration.writeConcernMax(), { - maxPoolSize: 1 - }); - - return client.connect().then(function (client) { - const db = client.db(configuration.db); - // LINE var MongoClient = require('mongodb').MongoClient, - // LINE test = require('assert'); - // LINE const client = new MongoClient('mongodb://localhost:27017/test'); - // LINE client.connect().then(() => { - // LINE var db = client.db('test); - // REPLACE configuration.writeConcernMax() WITH {w:1} - // REMOVE-LINE done(); - // BEGIN - - // Add a user to the database - return db - .addUser('user', 'name') - .then(function (result) { - expect(result).to.exist; - // Remove the user from the db - return db.removeUser('user'); - }) - .then(function (result) { - expect(result).to.exist; - return client.close(); - }); - }); - // END - } - }); - - /** - * An example of removing a user using a Promise. - * - * example-class Db - * example-method removeUser - */ - it.skip('shouldCorrectlyAddAndRemoveUserWithPromises', { - metadata: { requires: { topology: 'single', mongodb: '<=3.4.x' } }, - - test: function () { - const configuration = this.configuration; - - const client = configuration.newClient(); - return client.connect().then(function (client) { - const db = client.db(configuration.db); - // LINE var MongoClient = require('mongodb').MongoClient, - // LINE test = require('assert'); - // LINE const client = new MongoClient('mongodb://localhost:27017/test'); - // LINE client.connect().then(() => { - // LINE var db = client.db('test); - // REPLACE configuration.writeConcernMax() WITH {w:1} - // REMOVE-LINE done(); - // BEGIN - // Add a user to the database - - return db - .addUser('user3', 'name') - .then(function (result) { - expect(result).to.exist; - return client.close(); - }) - .then(() => { - const secondClient = configuration.newClient( - 'mongodb://user3:name@localhost:27017/integration_tests' - ); - - return secondClient.connect(); - }) - .then(function (client) { - // Logout the db - return client.logout().then(function () { - return client; - }); - }) - .then(function (client) { - // Remove the user - const db = client.db(configuration.db); - return db.removeUser('user3'); - }) - .then(function (result) { - expect(result).to.equal(true); - - // Should error out due to user no longer existing - const thirdClient = configuration.newClient( - 'mongodb://user3:name@localhost:27017/integration_tests', - { serverSelectionTimeoutMS: 10 } - ); - - return thirdClient.connect(); - }) - .catch(function (err) { - expect(err).to.exist; - return client.close(); - }); - }); - // END - } - }); - /** * A simple example showing the creation of a collection using a Promise. * @@ -3144,96 +3032,6 @@ describe('Operations', function () { } }); - /** - * An example of how to add a user to the admin database using a Promise. - * - * example-class Admin - * example-method addUser - */ - it('shouldCorrectlyAddAUserToAdminDbWithPromises', { - metadata: { requires: { topology: 'single' } }, - - test: function () { - const configuration = this.configuration; - const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - - return client.connect().then(function (client) { - const db = client.db(configuration.db); - // LINE var MongoClient = require('mongodb').MongoClient, - // LINE test = require('assert'); - // LINE const client = new MongoClient('mongodb://localhost:27017/test'); - // LINE client.connect().then(() => { - // LINE var db = client.db('test); - // REPLACE configuration.writeConcernMax() WITH {w:1} - // REMOVE-LINE restartAndDone - // REMOVE-LINE done(); - // BEGIN - - // Use the admin database for the operation - const adminDb = db.admin(); - - // Add the new user to the admin database - return adminDb - .addUser('admin11', 'admin11') - .then(function (result) { - expect(result).to.exist; - - return adminDb.removeUser('admin11'); - }) - .then(function (result) { - expect(result).to.exist; - return client.close(); - }); - }); - } - }); - - /** - * An example of how to remove a user from the admin database using a Promise. - * - * example-class Admin - * example-method removeUser - */ - it('shouldCorrectlyAddAUserAndRemoveItFromAdminDbWithPromises', { - metadata: { requires: { topology: 'single' } }, - - test: function () { - const configuration = this.configuration; - const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - - return client.connect().then(function (client) { - const db = client.db(configuration.db); - // LINE var MongoClient = require('mongodb').MongoClient, - // LINE test = require('assert'); - // LINE const client = new MongoClient('mongodb://localhost:27017/test'); - // LINE client.connect().then(() => { - // LINE var db = client.db('test); - // REPLACE configuration.writeConcernMax() WITH {w:1} - // REMOVE-LINE restartAndDone - // REMOVE-LINE done(); - // BEGIN - - // Use the admin database for the operation - const adminDb = db.admin(); - - // Add the new user to the admin database - return adminDb - .addUser('admin12', 'admin12') - .then(function (result) { - expect(result).to.exist; - - // Remove the user - return adminDb.removeUser('admin12'); - }) - .then(function (result) { - expect(result).to.equal(true); - return client.close(); - }); - }); - // END - } - }); - /** * An example of listing all available databases. using a Promise. * @@ -3307,11 +3105,6 @@ describe('Operations', function () { // Collections are not created until the first document is inserted return collection .insertOne({ a: 1 }, { writeConcern: { w: 1 } }) - .then(function (doc) { - expect(doc).to.exist; - // Add the new user to the admin database - return adminDb.addUser('admin13', 'admin13'); - }) .then(function (result) { expect(result).to.exist; // Retrieve the server Info diff --git a/test/integration/server-selection/readpreference.test.js b/test/integration/server-selection/readpreference.test.js index 41e8f052845..cfeeb3943ac 100644 --- a/test/integration/server-selection/readpreference.test.js +++ b/test/integration/server-selection/readpreference.test.js @@ -414,7 +414,14 @@ describe('ReadPreference', function () { }); const db = utilClient.db(configuration.db); - await db.addUser('default', 'pass', { roles: 'readWrite' }).catch(() => null); + await db + .command({ + createUser: 'default', + pwd: 'pass', + roles: [{ role: 'readWrite', db: configuration.db }] + }) + .catch(() => null); + await db.createCollection('before_collection').catch(() => null); await db.createIndex(collectionName, { aloha: 1 }).catch(() => null); @@ -430,7 +437,6 @@ describe('ReadPreference', function () { const methods = { 'Collection#createIndex': [{ quote: 'text' }], 'Db#createIndex': [collectionName, { quote: 'text' }], - 'Db#addUser': ['thomas', 'pass', { roles: 'readWrite' }], 'Db#removeUser': ['default'], 'Db#createCollection': ['created_collection'], 'Db#dropCollection': ['before_collection'], diff --git a/test/integration/uri-options/uri.test.js b/test/integration/uri-options/uri.test.js index ef62c3408bd..fc864927d29 100644 --- a/test/integration/uri-options/uri.test.js +++ b/test/integration/uri-options/uri.test.js @@ -88,8 +88,7 @@ describe('URI', function () { pass = '$specialch@rs'; var db = client.db(self.configuration.db); - db.addUser(user, pass, function (err) { - expect(err).to.not.exist; + db.command({ createUser: user, pwd: pass }).then(function () { var uri = 'mongodb://' + encodeURIComponent(user) + @@ -102,7 +101,7 @@ describe('URI', function () { c.close(() => client.close(done)); }); - }); + }, done); }); } }); diff --git a/test/mongodb.ts b/test/mongodb.ts index 53ea38256c0..4a8f21214b8 100644 --- a/test/mongodb.ts +++ b/test/mongodb.ts @@ -152,7 +152,6 @@ export * from '../src/gridfs/upload'; export * from '../src/mongo_client'; export * from '../src/mongo_logger'; export * from '../src/mongo_types'; -export * from '../src/operations/add_user'; export * from '../src/operations/aggregate'; export * from '../src/operations/bulk_write'; export * from '../src/operations/collections'; diff --git a/test/types/community/stats.test-d.ts b/test/types/community/stats.test-d.ts deleted file mode 100644 index a2904b5cfd7..00000000000 --- a/test/types/community/stats.test-d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { expectType } from 'tsd'; - -import { type CollStats, MongoClient } from '../../mongodb'; - -const client = new MongoClient(''); -const db = client.db('test'); -const collection = db.collection('test.find'); - -expectType(await collection.stats()); - -const stats = await collection.stats(); -if (stats.wiredTiger) { - expectType(stats.wiredTiger.cache['bytes currently in the cache']); -} diff --git a/test/unit/assorted/write_concern.test.js b/test/unit/assorted/write_concern.test.js index 46a33bdc592..6e45ca69dca 100644 --- a/test/unit/assorted/write_concern.test.js +++ b/test/unit/assorted/write_concern.test.js @@ -157,11 +157,6 @@ describe('Command Write Concern', function () { db.collection('test').dropIndexes(writeConcernTestOptions) )); - it('successfully pass through writeConcern to createUser command', () => - writeConcernTest('createUser', (db, writeConcernTestOptions) => - db.admin().addUser('kay:kay', 'abc123', writeConcernTestOptions) - )); - it('successfully pass through writeConcern to dropUser command', () => writeConcernTest('dropUser', (db, writeConcernTestOptions) => db.admin().removeUser('kay:kay', writeConcernTestOptions)