Skip to content

Commit 2291119

Browse files
authored
fix(NODE-3574): reintroduce ObjectID export (#2965)
1 parent 1be8e93 commit 2291119

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ export {
2929
Map
3030
} from './bson';
3131

32+
import { ObjectId } from 'bson';
33+
/**
34+
* @public
35+
* @deprecated Please use `ObjectId`
36+
*/
37+
export const ObjectID = ObjectId;
38+
3239
export {
3340
MongoError,
3441
MongoServerError,

test/types/mongodb.test-d.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { expectType, expectDeprecated, expectError } from 'tsd';
1+
import { expectType, expectDeprecated, expectNotDeprecated, expectError } from 'tsd';
22
import { MongoClient } from '../../src/mongo_client';
33
import { Collection } from '../../src/collection';
44
import { AggregationCursor } from '../../src/cursor/aggregation_cursor';
55
import type { FindCursor } from '../../src/cursor/find_cursor';
66
import type { Document } from 'bson';
77
import { Db } from '../../src';
88
import { Topology } from '../../src/sdam/topology';
9+
import * as MongoDBDriver from '../../src';
910

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

1922
// test mapped cursor types
2023
const client = new MongoClient('');

test/unit/bson_import.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,13 @@ describe('When importing BSON', function () {
8787
testTypes();
8888
});
8989
});
90+
91+
describe('MongoDB export', () => {
92+
const mongodb = require('../../src');
93+
it('should include ObjectId', () =>
94+
expect(mongodb).to.have.property('ObjectId').that.is.a('function'));
95+
it('should include ObjectID', () =>
96+
expect(mongodb).to.have.property('ObjectID').that.is.a('function'));
97+
it('should have ObjectID and ObjectId equal each other', () =>
98+
expect(mongodb.ObjectId).to.equal(mongodb.ObjectID));
99+
});

0 commit comments

Comments
 (0)