diff --git a/src/index.ts b/src/index.ts index ad62dff5a45..4a80f643bdd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,6 +29,13 @@ export { Map } from './bson'; +import { ObjectId } from 'bson'; +/** + * @public + * @deprecated Please use `ObjectId` + */ +export const ObjectID = ObjectId; + export { MongoError, MongoServerError, diff --git a/test/types/mongodb.test-d.ts b/test/types/mongodb.test-d.ts index bd16ce67950..3ec4f79db58 100644 --- a/test/types/mongodb.test-d.ts +++ b/test/types/mongodb.test-d.ts @@ -1,4 +1,4 @@ -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'; @@ -6,6 +6,7 @@ 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); @@ -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(''); diff --git a/test/unit/bson_import.test.js b/test/unit/bson_import.test.js index 28b3922b7da..e55c708d57e 100644 --- a/test/unit/bson_import.test.js +++ b/test/unit/bson_import.test.js @@ -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)); +});