Skip to content

Commit 63dca37

Browse files
Replaced mongodb.ObjectId() with the functions from mongo_utils.js
Signed-off-by: Aayush Chouhan <[email protected]>
1 parent b4e2f4d commit 63dca37

File tree

24 files changed

+169
-113
lines changed

24 files changed

+169
-113
lines changed

src/agent/block_store_speed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// const _ = require('lodash');
55
const argv = require('minimist')(process.argv);
66
const cluster = require('cluster');
7-
const mongodb = require('mongodb');
7+
const mongo_utils = require('../util/mongo_utils');
88

99
const api = require('../api');
1010
const config = require('../../config');
@@ -61,7 +61,7 @@ async function worker(client) {
6161
}
6262

6363
async function write_block(client) {
64-
const block_id = new mongodb.ObjectId();
64+
const block_id = new mongo_utils.ObjectId();
6565
return client.block_store.write_block({
6666
[RPC_BUFFERS]: { data: Buffer.allocUnsafe(argv.size) },
6767
block_md: {

src/sdk/nb.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export as namespace nb;
22

33
import * as fs from 'fs';
44
import * as mongodb from 'mongodb';
5+
import * as mongo_utils from '../util/mongo_utils';
56
import { EventEmitter } from 'events';
67
import { Readable, Writable } from 'stream';
78
import { IncomingMessage, ServerResponse } from 'http';
@@ -46,7 +47,7 @@ interface Base {
4647
toString?(): string;
4748
}
4849

49-
type ID = mongodb.ObjectID;
50+
type ID = string;
5051
type DBBuffer = mongodb.Binary | Buffer;
5152

5253
interface System extends Base {
@@ -719,8 +720,8 @@ interface DBClient {
719720
populate(docs: object[] | object, doc_path: string, collection: DBCollection, fields: object): Promise<object[] | object>;
720721
resolve_object_ids_recursive(idmap: object, item: object): object;
721722
resolve_object_ids_paths(idmap: object, item: object, paths: string[], allow_missing: boolean): object;
722-
new_object_id(): mongodb.ObjectId;
723-
parse_object_id(id_str: string): mongodb.ObjectId;
723+
new_object_id(): mongo_utils.ObjectId;
724+
parse_object_id(id_str: string): mongo_utils.ObjectId;
724725
fix_id_type(doc: object[] | object): object[] | object;
725726
is_object_id(id: object[] | object): boolean;
726727
is_err_duplicate_key(err: object): boolean;

src/server/analytic_services/activity_log_store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Copyright (C) 2016 NooBaa */
22
'use strict';
33

4-
const mongodb = require('mongodb');
4+
const mongo_utils = require('../../util/mongo_utils');
55
const _ = require('lodash');
66

77
const db_client = require('../../util/db_client');
@@ -25,7 +25,7 @@ class ActivityLogStore {
2525
}
2626

2727
make_activity_log_id(id_str) {
28-
return new mongodb.ObjectID(id_str);
28+
return new mongo_utils.ObjectId(id_str);
2929
}
3030

3131

src/server/analytic_services/history_data_store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Copyright (C) 2016 NooBaa */
22
'use strict';
33

4-
const mongodb = require('mongodb');
4+
const mongo_utils = require('../../util/mongo_utils');
55

66
// const dbg = require('../../util/debug_module')(__filename);
77
const config = require('../../../config.js');
@@ -30,7 +30,7 @@ class HistoryDataStore {
3030
const time_stamp = new Date();
3131
const record_expiration_date = new Date(time_stamp.getTime() - config.STATISTICS_COLLECTOR_EXPIRATION);
3232
const record = {
33-
_id: new mongodb.ObjectId(),
33+
_id: new mongo_utils.ObjectId(),
3434
time_stamp,
3535
system_snapshot: item,
3636
history_type: 'SYSTEM'

src/server/bg_services/mirror_writer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const util = require('util');
55
const _ = require('lodash');
6-
const { ObjectId } = require('mongodb');
6+
const { ObjectId } = require('../../util/mongo_utils');
77

88
const config = require('../../../config');
99
const dbg = require('../../util/debug_module')(__filename);

src/server/node_services/nodes_store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict';
33

44
const _ = require('lodash');
5-
const mongodb = require('mongodb');
5+
const mongo_utils = require('../../util/mongo_utils');
66

77
const dbg = require('../../util/debug_module')(__filename);
88
const node_schema = require('./node_schema');
@@ -24,7 +24,7 @@ class NodesStore {
2424
}
2525

2626
make_node_id(id_str) {
27-
return new mongodb.ObjectId(id_str);
27+
return new mongo_utils.ObjectId(id_str);
2828
}
2929

3030
is_connected() {

src/server/notifications/alerts_log_store.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Copyright (C) 2016 NooBaa */
22
'use strict';
33

4-
const mongodb = require('mongodb');
4+
const mongo_utils = require('../../util/mongo_utils');
55
const _ = require('lodash');
66
const P = require('../../util/promise');
77
const db_client = require('../../util/db_client');
@@ -23,7 +23,7 @@ class AlertsLogStore {
2323
}
2424

2525
make_alert_log_id(id_str) {
26-
return new mongodb.ObjectID(id_str);
26+
return new mongo_utils.ObjectId(id_str);
2727
}
2828

2929
create(alert_log) {
@@ -94,12 +94,12 @@ class AlertsLogStore {
9494

9595
let _id;
9696
if (ids) {
97-
const obj_ids = ids.map(id => new mongodb.ObjectID(id));
97+
const obj_ids = ids.map(id => new mongo_utils.ObjectId(id));
9898
_id = { $in: obj_ids };
9999
} else if (till) {
100-
_id = { $lt: new mongodb.ObjectID(till) };
100+
_id = { $lt: new mongo_utils.ObjectId(till) };
101101
} else if (since) {
102-
_id = { $gt: new mongodb.ObjectID(since) };
102+
_id = { $gt: new mongo_utils.ObjectId(since) };
103103
}
104104

105105
return _.omitBy({

src/server/object_services/md_store.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const _ = require('lodash');
88
const assert = require('assert');
99
const moment = require('moment');
10-
const mongodb = require('mongodb');
10+
const mongo_utils = require('../../util/mongo_utils');
1111
const mime = require('mime-types');
1212

1313
const P = require('../../util/promise');
@@ -92,18 +92,18 @@ class MDStore {
9292
if (zero_suffix) {
9393
suffix = '0'.repeat(16);
9494
} else {
95-
suffix = String(new mongodb.ObjectId()).slice(8, 24);
95+
suffix = String(new mongo_utils.ObjectId()).slice(8, 24);
9696
}
9797
const hex_id = padded_hex_time + suffix;
9898
assert(padded_hex_time.length === 8);
9999
assert(suffix.length === 16);
100100
assert(hex_id.length === 24);
101101
assert(parseInt(padded_hex_time, 16) === Math.floor(time / 1000));
102-
return new mongodb.ObjectId(hex_id);
102+
return new mongo_utils.ObjectId(hex_id);
103103
}
104104

105105
is_valid_md_id(id_str) {
106-
return mongodb.ObjectId.isValid(id_str);
106+
return mongo_utils.ObjectId.isValid(id_str);
107107
}
108108

109109
/////////////
@@ -2113,7 +2113,7 @@ function sort_list_uploads_with_delimiter(a, b) {
21132113
* @returns {nb.ID}
21142114
*/
21152115
function make_md_id(id_str) {
2116-
return new mongodb.ObjectId(id_str);
2116+
return new mongo_utils.ObjectId(id_str);
21172117
}
21182118

21192119

src/server/system_services/config_file_store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const _ = require('lodash');
55
const dbg = require('../../util/debug_module')(__filename);
66
const db_client = require('../../util/db_client');
7-
const mongodb = require('mongodb');
7+
const mongo_utils = require('../../util/mongo_utils');
88
const config_file_schema = require('./schemas/config_file_schema');
99
const config_file_indexes = require('./schemas/config_file_indexes');
1010

@@ -26,7 +26,7 @@ class ConfigFileStore {
2626
async insert(item) {
2727
dbg.log0(`insert`, item);
2828
_.defaults(item, {
29-
_id: new mongodb.ObjectId()
29+
_id: new mongo_utils.ObjectId()
3030
});
3131
// There shouldn't be more than one record, this is being on the safe side
3232
this._config_files.validate(item);

src/server/system_services/replication_store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict';
33

44
const _ = require('lodash');
5-
const mongodb = require('mongodb');
5+
const mongo_utils = require('../../util/mongo_utils');
66
const db_client = require('../../util/db_client');
77
const dbg = require('../../util/debug_module')(__filename);
88
const replication_schema = require('./schemas/replication_configuration_schema');
@@ -25,7 +25,7 @@ class ReplicationStore {
2525
item = _.omitBy(item, _.isNil);
2626
dbg.log1(`insert_replication`, item);
2727
const record = {
28-
_id: new mongodb.ObjectId(),
28+
_id: new mongo_utils.ObjectId(),
2929
...item
3030
};
3131
this._replicationconfigs.validate(record);

0 commit comments

Comments
 (0)