Skip to content

Commit

Permalink
fix(NODE-3574): reintroduce ObjectID export (#2965)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken authored Sep 7, 2021
1 parent 1be8e93 commit 2291119
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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));
});

0 comments on commit 2291119

Please sign in to comment.