{"size": 1672, "ext": "js", "max_stars_repo_path": "test/qa-tests/jstests/restore/extended_json_metadata.js", "max_stars_repo_name": "tfogo/mongo-tools", "max_stars_repo_stars_event_min_datetime": "2015-01-02T17:43:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T14:04:31.000Z", "max_issues_repo_path": "test/qa-tests/jstests/restore/extended_json_metadata.js", "max_issues_repo_name": "tfogo/mongo-tools", "max_issues_repo_issues_event_min_datetime": "2015-03-02T11:58:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-14T16:38:29.000Z", "max_forks_repo_path": "test/qa-tests/jstests/restore/extended_json_metadata.js", "max_forks_repo_name": "tfogo/mongo-tools", "max_forks_repo_forks_event_min_datetime": "2015-01-15T19:19:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T06:50:08.000Z"}
{"max_stars_count": 828, "max_issues_count": 216, "max_forks_count": 394, "avg_line_length": 38.8837209302, "max_line_length": 94, "alphanum_fraction": 0.7350478469}
(function() {

  if (typeof getToolTest === 'undefined') {
    load('jstests/configs/plain_28.config.js');
  }

  if (dump_targets !== "standard") {
    print('skipping test incompatable with archiving or compression');
    return assert(true);
  }

  // Tests that using mongorestore on a collection with extended json types
  // in the metadata (both indexes and options) is handled gracefully.

  jsTest.log('Testing that restoration of extended JSON collection options works.');

  var toolTest = getToolTest('extended_json_metadata_restore');
  var commonToolArgs = getCommonToolArguments();
  var testDB = toolTest.db.getSiblingDB('test');
  assert.eq(testDB.changelog.exists(), null, "collection already exists in db");

  // run a restore against the mongos
  var ret = toolTest.runTool.apply(toolTest, ['restore']
    .concat(getRestoreTarget('jstests/restore/testdata/dump_extended_json_options'))
    .concat(commonToolArgs));
  assert.eq(0, ret, "the restore does not crash");

  var collectionOptionsFromDB = testDB.changelog.exists();
  printjson(collectionOptionsFromDB);
  assert.eq(collectionOptionsFromDB.options.capped, true, "capped option should be restored");
  // Mongodb might fudge the collection max values for different storage engines,
  // so we need some wiggle room.
  var delta = 1000;
  var size = 10 * 1000 * 1000;
  assert.lte(collectionOptionsFromDB.options.size, size+delta, "size should be ~10000000");
  assert.gte(collectionOptionsFromDB.options.size, size-delta, "size should be ~10000000");

  var indexes = testDB.changelog.getIndexes();
  printjson(indexes);
  assert.eq(indexes[0].key._id, 1, "index is read properly");

}());
