Skip to content

fix(NODE-3574): reintroduce ObjectID export #2965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 7, 2021
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
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export {
Map
} from './bson';

import { ObjectId } from 'bson';
/**
* @public
* @deprecated Please use `ObjectId`
*/
export const ObjectID = ObjectId;

export {
MongoError,
MongoServerError,
Expand Down
5 changes: 4 additions & 1 deletion test/types/mongodb.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { expectType, expectDeprecated, expectError } from 'tsd';
import { expectType, expectDeprecated, expectNotDeprecated, expectError } from 'tsd';
import { MongoClient } from '../../src/mongo_client';
import { Collection } from '../../src/collection';
import { AggregationCursor } from '../../src/cursor/aggregation_cursor';
import type { FindCursor } from '../../src/cursor/find_cursor';
import type { Document } from 'bson';
import { Db } from '../../src';
import { Topology } from '../../src/sdam/topology';
import * as MongoDBDriver from '../../src';

// We wish to keep these APIs but continue to ensure they are marked as deprecated.
expectDeprecated(Collection.prototype.insert);
Expand All @@ -15,6 +16,8 @@ expectDeprecated(Collection.prototype.count);
expectDeprecated(AggregationCursor.prototype.geoNear);
expectDeprecated(Topology.prototype.unref);
expectDeprecated(Db.prototype.unref);
expectDeprecated(MongoDBDriver.ObjectID);
expectNotDeprecated(MongoDBDriver.ObjectId);

// test mapped cursor types
const client = new MongoClient('');
Expand Down
10 changes: 10 additions & 0 deletions test/unit/bson_import.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,13 @@ describe('When importing BSON', function () {
testTypes();
});
});

describe('MongoDB export', () => {
const mongodb = require('../../src');
it('should include ObjectId', () =>
expect(mongodb).to.have.property('ObjectId').that.is.a('function'));
it('should include ObjectID', () =>
expect(mongodb).to.have.property('ObjectID').that.is.a('function'));
it('should have ObjectID and ObjectId equal each other', () =>
expect(mongodb.ObjectId).to.equal(mongodb.ObjectID));
});