Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/shell-api/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ export default class Collection extends ShellApiWithMongoClass {
*/
@returnType('Cursor')
@apiVersions([1])
find(query?: Document, projection?: Document): Cursor {
const options: FindOptions = {};
find(query?: Document, projection?: Document, options: FindOptions = {}): Cursor {
if (projection) {
options.projection = projection;
}
Expand Down Expand Up @@ -463,8 +462,7 @@ export default class Collection extends ShellApiWithMongoClass {
@returnsPromise
@returnType('Document')
@apiVersions([1])
async findOne(query: Document = {}, projection?: Document): Promise<Document | null> {
const options: any = {};
async findOne(query: Document = {}, projection?: Document, options: FindOptions = {}): Promise<Document | null> {
if (projection) {
options.projection = projection;
}
Expand Down
38 changes: 38 additions & 0 deletions packages/shell-api/src/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,44 @@ describe('Shell API (integration)', function() {
});
});
});

describe('find', () => {
it('uses default options for the driver (find)', async() => {
const longOne = new serviceProvider.bsonLibrary.Long('1');
await serviceProvider.insertOne(dbName, collectionName, { longOne, _id: 0 });

const cursor = await collection.find({});

expect(await cursor.toArray()).to.deep.equal([{ longOne, _id: 0 }]);
});

it('passes through options to the driver (find)', async() => {
const longOne = new serviceProvider.bsonLibrary.Long('1');
await serviceProvider.insertOne(dbName, collectionName, { longOne, _id: 0 });

const cursor = await collection.find({}, {}, { promoteLongs: true });

expect(await cursor.toArray()).to.deep.equal([{ longOne: 1, _id: 0 }]);
});

it('uses default options for the driver (findOne)', async() => {
const longOne = new serviceProvider.bsonLibrary.Long('1');
await serviceProvider.insertOne(dbName, collectionName, { longOne, _id: 0 });

const doc = await collection.findOne({});

expect(doc).to.deep.equal({ longOne, _id: 0 });
});

it('passes through options to the driver (findOne)', async() => {
const longOne = new serviceProvider.bsonLibrary.Long('1');
await serviceProvider.insertOne(dbName, collectionName, { longOne, _id: 0 });

const doc = await collection.findOne({}, {}, { promoteLongs: true });

expect(doc).to.deep.equal({ longOne: 1, _id: 0 });
});
});
});

describe('db', () => {
Expand Down