Skip to content

Commit

Permalink
create collection
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Aug 23, 2024
1 parent d0a7562 commit 665e040
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
13 changes: 9 additions & 4 deletions test/integration/crud/crud.prose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { expect } from 'chai';
import { once } from 'events';

import { type CommandStartedEvent } from '../../../mongodb';
import { MongoBulkWriteError, type MongoClient, MongoServerError } from '../../mongodb';
import {
type Collection,
MongoBulkWriteError,
type MongoClient,
MongoServerError
} from '../../mongodb';
import { filterForCommands } from '../shared';

describe('CRUD Prose Spec Tests', () => {
Expand Down Expand Up @@ -149,11 +154,14 @@ describe('CRUD Prose Spec Tests', () => {
describe('14. `explain` helpers allow users to specify `maxTimeMS`', function () {
let client: MongoClient;
const commands: CommandStartedEvent[] = [];
let collection: Collection;

beforeEach(async function () {
client = this.configuration.newClient({}, { monitorCommands: true });
await client.connect();

collection = await client.db('explain-test').createCollection('collection');

client.on('commandStarted', filterForCommands('explain', commands));
commands.length = 0;
});
Expand All @@ -163,9 +171,6 @@ describe('CRUD Prose Spec Tests', () => {
});

it('sets maxTimeMS on explain commands, when specfied', async function () {
// Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
const collection = client.db('explain-test').collection('collection');

await collection
.find(
{ name: 'john doe' },
Expand Down
20 changes: 4 additions & 16 deletions test/integration/crud/explain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,14 @@ describe('CRUD API explain option', function () {
describe('explain helpers w/ maxTimeMS', function () {
let client: MongoClient;
const commands: CommandStartedEvent[] = [];
let collection: Collection;

beforeEach(async function () {
client = this.configuration.newClient({}, { monitorCommands: true });
await client.connect();

collection = await client.db('explain-test').createCollection('bar');

client.on('commandStarted', filterForCommands('explain', commands));
commands.length = 0;
});
Expand All @@ -139,7 +142,6 @@ describe('CRUD API explain option', function () {
describe('cursor explain commands', function () {
describe('when maxTimeMS is specified via a cursor explain method, it sets the property on the command', function () {
test('find()', async function () {
const collection = client.db('explain-test').collection('collection');
await collection
.find({ name: 'john doe' })
.explain({ maxTimeMS: 2000, verbosity: 'queryPlanner' });
Expand All @@ -149,8 +151,6 @@ describe('CRUD API explain option', function () {
});

test('aggregate()', async function () {
const collection = client.db('explain-test').collection('collection');

await collection
.aggregate([{ $match: { name: 'john doe' } }])
.explain({ maxTimeMS: 2000, verbosity: 'queryPlanner' });
Expand All @@ -161,19 +161,13 @@ describe('CRUD API explain option', function () {
});

it('when maxTimeMS is not specified, it is not attached to the explain command', async function () {
// Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
const collection = client.db('explain-test').collection('collection');

await collection.find({ name: 'john doe' }).explain({ verbosity: 'queryPlanner' });

const [{ command }] = commands;
expect(command).not.to.have.property('maxTimeMS');
});

it('when maxTimeMS is specified as an explain option and a command-level option, the explain option takes precedence', async function () {
// Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
const collection = client.db('explain-test').collection('collection');

await collection
.find(
{},
Expand All @@ -194,15 +188,12 @@ describe('CRUD API explain option', function () {

describe('regular commands w/ explain', function () {
it('when maxTimeMS is specified as an explain option and a command-level option, the explain option takes precedence', async function () {
// Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
const collection = client.db('explain-test').collection('collection');

await collection.deleteMany(
{},
{
maxTimeMS: 1000,
explain: {
verbosity: true,
verbosity: 'queryPlanner',
maxTimeMS: 2000
}
}
Expand All @@ -214,7 +205,6 @@ describe('CRUD API explain option', function () {

describe('when maxTimeMS is specified as an explain option', function () {
it('attaches maxTimeMS to the explain command', async function () {
const collection = client.db('explain-test').collection('collection');
await collection.deleteMany(
{},
{ explain: { maxTimeMS: 2000, verbosity: 'queryPlanner' } }
Expand All @@ -226,8 +216,6 @@ describe('CRUD API explain option', function () {
});

it('when maxTimeMS is not specified, it is not attached to the explain command', async function () {
const collection = client.db('explain-test').collection('collection');

await collection.deleteMany({}, { explain: { verbosity: 'queryPlanner' } });

const [{ command }] = commands;
Expand Down

0 comments on commit 665e040

Please sign in to comment.