summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Banala <arun.banala@mongodb.com>2020-11-12 17:48:52 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-11-12 18:15:38 +0000
commit7c196029e8529d8d217a4c9314d8a4e6069a91d2 (patch)
treedcac2d4dda9015804fbf538cffd4a15d9c02cd39
parentccd024d9fb5c0587e33a3a3321e7f9a0430d0190 (diff)
downloadmongo-7c196029e8529d8d217a4c9314d8a4e6069a91d2.tar.gz
Revert "SERVER-50442 Remove ensureIndex shell function This commit also replaces all the usages of ensureIndex() with createIndex() in JS tests and JS shell"
This reverts commit e69c967ff8b53634770438dfe9a5c7d13548351b.
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_causal_consistency.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_causal_consistency_and_balancer.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_kill_primary_with_balancer.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_local_read_write_multi_stmt_txn.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_local_read_write_multi_stmt_txn_with_balancer.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_kill_primary.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_terminate_primary.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_with_balancer.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_with_stepdowns.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_replication.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_replication_with_balancer.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_terminate_primary_with_balancer.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_with_stepdowns.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded_with_stepdowns_and_balancer.yml2
-rw-r--r--jstests/aggregation/bugs/server12015.js2
-rw-r--r--jstests/aggregation/bugs/server13715.js2
-rw-r--r--jstests/aggregation/bugs/server14969.js2
-rw-r--r--jstests/aggregation/bugs/server22093.js2
-rw-r--r--jstests/aggregation/bugs/server3253.js6
-rw-r--r--jstests/aggregation/bugs/server3832.js4
-rw-r--r--jstests/aggregation/bugs/server6531.js4
-rw-r--r--jstests/aggregation/bugs/server7781.js2
-rw-r--r--jstests/aggregation/bugs/sort_arrays.js2
-rw-r--r--jstests/auth/basic_role_auth.js2
-rw-r--r--jstests/auth/lib/commands_lib.js2
-rw-r--r--jstests/auth/readIndex.js2
-rw-r--r--jstests/concurrency/fsm_example_inheritance.js2
-rw-r--r--jstests/concurrency/fsm_workloads/agg_out.js8
-rw-r--r--jstests/concurrency/fsm_workloads/collmod.js2
-rw-r--r--jstests/concurrency/fsm_workloads/compact.js6
-rw-r--r--jstests/concurrency/fsm_workloads/convert_to_capped_collection_index.js2
-rw-r--r--jstests/concurrency/fsm_workloads/count_indexed.js2
-rw-r--r--jstests/concurrency/fsm_workloads/create_index_background.js2
-rw-r--r--jstests/concurrency/fsm_workloads/distinct.js2
-rw-r--r--jstests/concurrency/fsm_workloads/explain.js2
-rw-r--r--jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js4
-rw-r--r--jstests/concurrency/fsm_workloads/findAndModify_update.js2
-rw-r--r--jstests/concurrency/fsm_workloads/indexed_insert_text.js2
-rw-r--r--jstests/concurrency/fsm_workloads/indexed_insert_ttl.js2
-rw-r--r--jstests/concurrency/fsm_workloads/indexed_insert_where.js2
-rw-r--r--jstests/concurrency/fsm_workloads/list_indexes.js4
-rw-r--r--jstests/concurrency/fsm_workloads/update_array.js2
-rw-r--r--jstests/concurrency/fsm_workloads/update_check_index.js6
-rw-r--r--jstests/concurrency/fsm_workloads/update_multifield.js8
-rw-r--r--jstests/concurrency/fsm_workloads/update_rename.js2
-rw-r--r--jstests/concurrency/fsm_workloads/update_replace.js8
-rw-r--r--jstests/concurrency/fsm_workloads/update_simple.js2
-rw-r--r--jstests/concurrency/fsm_workloads/update_upsert_multi.js2
-rw-r--r--jstests/concurrency/fsm_workloads/yield_geo_near.js2
-rw-r--r--jstests/concurrency/fsm_workloads/yield_rooted_or.js4
-rw-r--r--jstests/concurrency/fsm_workloads/yield_sort_merge.js2
-rw-r--r--jstests/concurrency/fsm_workloads/yield_text.js2
-rw-r--r--jstests/core/all.js2
-rw-r--r--jstests/core/all2.js6
-rw-r--r--jstests/core/and.js2
-rw-r--r--jstests/core/and3.js2
-rw-r--r--jstests/core/andor.js4
-rw-r--r--jstests/core/apitest_dbcollection.js14
-rw-r--r--jstests/core/array1.js2
-rw-r--r--jstests/core/array_match1.js4
-rw-r--r--jstests/core/array_match3.js2
-rw-r--r--jstests/core/array_match4.js2
-rw-r--r--jstests/core/arrayfind1.js2
-rw-r--r--jstests/core/arrayfind2.js2
-rw-r--r--jstests/core/arrayfind3.js2
-rw-r--r--jstests/core/arrayfind4.js2
-rw-r--r--jstests/core/arrayfind5.js4
-rw-r--r--jstests/core/arrayfind6.js2
-rw-r--r--jstests/core/arrayfind7.js4
-rw-r--r--jstests/core/arrayfind9.js4
-rw-r--r--jstests/core/arrayfinda.js2
-rw-r--r--jstests/core/arrayfindb.js6
-rw-r--r--jstests/core/bad_index_plugin.js4
-rw-r--r--jstests/core/basic7.js2
-rw-r--r--jstests/core/batch_size.js10
-rw-r--r--jstests/core/batch_write_command_insert.js8
-rw-r--r--jstests/core/batch_write_command_update.js4
-rw-r--r--jstests/core/batch_write_command_w0.js2
-rw-r--r--jstests/core/bulk_api_ordered.js6
-rw-r--r--jstests/core/bulk_api_unordered.js6
-rw-r--r--jstests/core/capped5.js8
-rw-r--r--jstests/core/capped_empty.js2
-rw-r--r--jstests/core/cappeda.js2
-rw-r--r--jstests/core/check_shard_index.js14
-rw-r--r--jstests/core/collation.js68
-rw-r--r--jstests/core/collmod.js6
-rw-r--r--jstests/core/compact_keeps_indexes.js2
-rw-r--r--jstests/core/count.js4
-rw-r--r--jstests/core/count4.js2
-rw-r--r--jstests/core/count5.js2
-rw-r--r--jstests/core/count6.js2
-rw-r--r--jstests/core/count7.js2
-rw-r--r--jstests/core/count9.js6
-rw-r--r--jstests/core/count_hint.js4
-rw-r--r--jstests/core/countb.js2
-rw-r--r--jstests/core/countc.js22
-rw-r--r--jstests/core/coveredIndex2.js2
-rw-r--r--jstests/core/coveredIndex3.js2
-rw-r--r--jstests/core/coveredIndex4.js4
-rw-r--r--jstests/core/covered_index_compound_1.js2
-rw-r--r--jstests/core/covered_index_negative_1.js8
-rw-r--r--jstests/core/covered_index_simple_1.js2
-rw-r--r--jstests/core/covered_index_simple_2.js2
-rw-r--r--jstests/core/covered_index_simple_3.js4
-rw-r--r--jstests/core/covered_index_sort_1.js2
-rw-r--r--jstests/core/covered_index_sort_3.js2
-rw-r--r--jstests/core/create_index_helper_validation.js2
-rw-r--r--jstests/core/crud_api.js2
-rw-r--r--jstests/core/cursor3.js2
-rw-r--r--jstests/core/cursor4.js2
-rw-r--r--jstests/core/cursor5.js2
-rw-r--r--jstests/core/cursor6.js2
-rw-r--r--jstests/core/cursor7.js2
-rw-r--r--jstests/core/date2.js2
-rw-r--r--jstests/core/date3.js2
-rw-r--r--jstests/core/distinct3.js4
-rw-r--r--jstests/core/distinct_array1.js6
-rw-r--r--jstests/core/distinct_index2.js6
-rw-r--r--jstests/core/drop.js4
-rw-r--r--jstests/core/drop_index.js2
-rw-r--r--jstests/core/dropdb_race.js2
-rw-r--r--jstests/core/exists.js8
-rw-r--r--jstests/core/exists2.js2
-rw-r--r--jstests/core/exists3.js2
-rw-r--r--jstests/core/exists4.js2
-rw-r--r--jstests/core/exists6.js4
-rw-r--r--jstests/core/exists7.js2
-rw-r--r--jstests/core/exists9.js6
-rw-r--r--jstests/core/existsa.js4
-rw-r--r--jstests/core/existsb.js8
-rw-r--r--jstests/core/explain1.js2
-rw-r--r--jstests/core/explain4.js2
-rw-r--r--jstests/core/explain5.js4
-rw-r--r--jstests/core/explain6.js4
-rw-r--r--jstests/core/explain_count.js2
-rw-r--r--jstests/core/explain_delete.js2
-rw-r--r--jstests/core/explain_execution_error.js4
-rw-r--r--jstests/core/explain_find.js2
-rw-r--r--jstests/core/explain_large_bounds.js2
-rw-r--r--jstests/core/explain_multi_plan.js4
-rw-r--r--jstests/core/explain_shell_helpers.js4
-rw-r--r--jstests/core/expr.js2
-rw-r--r--jstests/core/filemd5.js2
-rw-r--r--jstests/core/find6.js2
-rw-r--r--jstests/core/find_and_modify_concurrent_update.js4
-rw-r--r--jstests/core/find_dedup.js2
-rw-r--r--jstests/core/finda.js4
-rw-r--r--jstests/core/fts2.js2
-rw-r--r--jstests/core/fts3.js2
-rw-r--r--jstests/core/fts4.js2
-rw-r--r--jstests/core/fts5.js2
-rw-r--r--jstests/core/fts6.js4
-rw-r--r--jstests/core/fts_blog.js2
-rw-r--r--jstests/core/fts_blogwild.js4
-rw-r--r--jstests/core/fts_casesensitive.js2
-rw-r--r--jstests/core/fts_diacritic_and_caseinsensitive.js2
-rw-r--r--jstests/core/fts_diacritic_and_casesensitive.js2
-rw-r--r--jstests/core/fts_diacriticsensitive.js2
-rw-r--r--jstests/core/fts_explain.js2
-rw-r--r--jstests/core/fts_index.js86
-rw-r--r--jstests/core/fts_index2.js2
-rw-r--r--jstests/core/fts_index3.js24
-rw-r--r--jstests/core/fts_index_version1.js6
-rw-r--r--jstests/core/fts_index_version2.js2
-rw-r--r--jstests/core/fts_mix.js10
-rw-r--r--jstests/core/fts_partition1.js2
-rw-r--r--jstests/core/fts_partition_no_multikey.js2
-rw-r--r--jstests/core/fts_phrase.js2
-rw-r--r--jstests/core/geo1.js6
-rw-r--r--jstests/core/geo10.js2
-rw-r--r--jstests/core/geo2.js2
-rw-r--r--jstests/core/geo3.js6
-rw-r--r--jstests/core/geo6.js2
-rw-r--r--jstests/core/geo7.js4
-rw-r--r--jstests/core/geo9.js4
-rw-r--r--jstests/core/geo_2d_explain.js2
-rw-r--r--jstests/core/geo_2d_with_geojson_point.js2
-rw-r--r--jstests/core/geo_allowedcomparisons.js4
-rw-r--r--jstests/core/geo_array0.js2
-rw-r--r--jstests/core/geo_array1.js2
-rw-r--r--jstests/core/geo_array2.js2
-rw-r--r--jstests/core/geo_big_polygon.js8
-rw-r--r--jstests/core/geo_big_polygon2.js10
-rw-r--r--jstests/core/geo_big_polygon3.js4
-rw-r--r--jstests/core/geo_borders.js4
-rw-r--r--jstests/core/geo_box1.js2
-rw-r--r--jstests/core/geo_box2.js4
-rw-r--r--jstests/core/geo_box3.js8
-rw-r--r--jstests/core/geo_center_sphere1.js2
-rw-r--r--jstests/core/geo_center_sphere2.js2
-rw-r--r--jstests/core/geo_circle1.js2
-rw-r--r--jstests/core/geo_circle2.js2
-rw-r--r--jstests/core/geo_circle2a.js6
-rw-r--r--jstests/core/geo_circle3.js2
-rw-r--r--jstests/core/geo_circle4.js2
-rw-r--r--jstests/core/geo_circle5.js2
-rw-r--r--jstests/core/geo_exactfetch.js2
-rw-r--r--jstests/core/geo_fiddly_box.js4
-rw-r--r--jstests/core/geo_fiddly_box2.js6
-rw-r--r--jstests/core/geo_invalid_2d_params.js10
-rw-r--r--jstests/core/geo_mindistance.js2
-rw-r--r--jstests/core/geo_mindistance_boundaries.js2
-rw-r--r--jstests/core/geo_multikey0.js4
-rw-r--r--jstests/core/geo_multikey1.js4
-rw-r--r--jstests/core/geo_multinest0.js4
-rw-r--r--jstests/core/geo_multinest1.js2
-rw-r--r--jstests/core/geo_near_bounds_overflow.js2
-rw-r--r--jstests/core/geo_near_random1.js2
-rw-r--r--jstests/core/geo_near_random2.js2
-rw-r--r--jstests/core/geo_nearwithin.js2
-rw-r--r--jstests/core/geo_oob_sphere.js2
-rw-r--r--jstests/core/geo_operator_crs.js6
-rw-r--r--jstests/core/geo_or.js4
-rw-r--r--jstests/core/geo_poly_edge.js2
-rw-r--r--jstests/core/geo_poly_line.js2
-rw-r--r--jstests/core/geo_polygon1.js4
-rw-r--r--jstests/core/geo_polygon2.js2
-rw-r--r--jstests/core/geo_queryoptimizer.js2
-rw-r--r--jstests/core/geo_regex0.js2
-rw-r--r--jstests/core/geo_s2cursorlimitskip.js2
-rw-r--r--jstests/core/geo_s2dedupnear.js2
-rw-r--r--jstests/core/geo_s2descindex.js4
-rw-r--r--jstests/core/geo_s2dupe_points.js2
-rw-r--r--jstests/core/geo_s2edgecases.js2
-rw-r--r--jstests/core/geo_s2exact.js2
-rw-r--r--jstests/core/geo_s2explain.js2
-rw-r--r--jstests/core/geo_s2holesameasshell.js2
-rw-r--r--jstests/core/geo_s2index.js22
-rw-r--r--jstests/core/geo_s2indexoldformat.js2
-rw-r--r--jstests/core/geo_s2indexversion1.js46
-rw-r--r--jstests/core/geo_s2intersection.js4
-rw-r--r--jstests/core/geo_s2largewithin.js2
-rw-r--r--jstests/core/geo_s2meridian.js6
-rw-r--r--jstests/core/geo_s2multi.js2
-rw-r--r--jstests/core/geo_s2near.js4
-rw-r--r--jstests/core/geo_s2nearComplex.js14
-rw-r--r--jstests/core/geo_s2near_equator_opposite.js2
-rw-r--r--jstests/core/geo_s2nearcorrect.js2
-rw-r--r--jstests/core/geo_s2nearwithin.js2
-rw-r--r--jstests/core/geo_s2nongeoarray.js6
-rw-r--r--jstests/core/geo_s2nonstring.js4
-rw-r--r--jstests/core/geo_s2nopoints.js2
-rw-r--r--jstests/core/geo_s2oddshapes.js6
-rw-r--r--jstests/core/geo_s2ordering.js2
-rw-r--r--jstests/core/geo_s2overlappingpolys.js2
-rw-r--r--jstests/core/geo_s2polywithholes.js2
-rw-r--r--jstests/core/geo_s2selfintersectingpoly.js2
-rw-r--r--jstests/core/geo_s2sparse.js6
-rw-r--r--jstests/core/geo_s2twofields.js2
-rw-r--r--jstests/core/geo_s2validindex.js8
-rw-r--r--jstests/core/geo_s2within.js4
-rw-r--r--jstests/core/geo_small_large.js2
-rw-r--r--jstests/core/geo_sort1.js2
-rw-r--r--jstests/core/geo_uniqueDocs.js2
-rw-r--r--jstests/core/geo_uniqueDocs2.js4
-rw-r--r--jstests/core/geo_update.js2
-rw-r--r--jstests/core/geo_update1.js2
-rw-r--r--jstests/core/geo_update2.js2
-rw-r--r--jstests/core/geo_update_btree.js2
-rw-r--r--jstests/core/geo_update_btree2.js2
-rw-r--r--jstests/core/geo_update_dedup.js10
-rw-r--r--jstests/core/geo_validate.js2
-rw-r--r--jstests/core/geoa.js2
-rw-r--r--jstests/core/geob.js2
-rw-r--r--jstests/core/geoc.js2
-rw-r--r--jstests/core/geod.js2
-rw-r--r--jstests/core/geoe.js2
-rw-r--r--jstests/core/geof.js2
-rw-r--r--jstests/core/geonear_cmd_input_validation.js2
-rw-r--r--jstests/core/getmore_invalidated_documents.js22
-rw-r--r--jstests/core/hint1.js2
-rw-r--r--jstests/core/idhack.js2
-rw-r--r--jstests/core/in.js2
-rw-r--r--jstests/core/in2.js2
-rw-r--r--jstests/core/in3.js2
-rw-r--r--jstests/core/in4.js2
-rw-r--r--jstests/core/in5.js4
-rw-r--r--jstests/core/in6.js2
-rw-r--r--jstests/core/in8.js2
-rw-r--r--jstests/core/inc1.js2
-rw-r--r--jstests/core/inc2.js2
-rw-r--r--jstests/core/index1.js2
-rw-r--r--jstests/core/index13.js14
-rw-r--r--jstests/core/index2.js2
-rw-r--r--jstests/core/index3.js4
-rw-r--r--jstests/core/index4.js4
-rw-r--r--jstests/core/index5.js2
-rw-r--r--jstests/core/index6.js2
-rw-r--r--jstests/core/index8.js12
-rw-r--r--jstests/core/index_arr1.js4
-rw-r--r--jstests/core/index_arr2.js6
-rw-r--r--jstests/core/index_bounds_number_edge_cases.js2
-rw-r--r--jstests/core/index_check2.js2
-rw-r--r--jstests/core/index_check3.js6
-rw-r--r--jstests/core/index_check5.js2
-rw-r--r--jstests/core/index_check6.js4
-rw-r--r--jstests/core/index_check7.js4
-rw-r--r--jstests/core/index_diag.js2
-rw-r--r--jstests/core/index_dropdups_ignore.js4
-rw-r--r--jstests/core/index_id_options.js36
-rw-r--r--jstests/core/index_many.js2
-rw-r--r--jstests/core/index_many2.js4
-rw-r--r--jstests/core/index_partial_validate.js4
-rw-r--r--jstests/core/index_partial_write_ops.js2
-rw-r--r--jstests/core/index_sparse1.js10
-rw-r--r--jstests/core/index_sparse2.js4
-rw-r--r--jstests/core/index_type_change.js2
-rw-r--r--jstests/core/indexa.js2
-rw-r--r--jstests/core/indexapi.js4
-rw-r--r--jstests/core/indexb.js2
-rw-r--r--jstests/core/indexc.js4
-rw-r--r--jstests/core/indexe.js2
-rw-r--r--jstests/core/indexf.js2
-rw-r--r--jstests/core/indexg.js2
-rw-r--r--jstests/core/indexj.js6
-rw-r--r--jstests/core/indexl.js2
-rw-r--r--jstests/core/indexm.js4
-rw-r--r--jstests/core/indexn.js4
-rw-r--r--jstests/core/indexp.js22
-rw-r--r--jstests/core/indexr.js4
-rw-r--r--jstests/core/indexs.js6
-rw-r--r--jstests/core/indext.js4
-rw-r--r--jstests/core/indexu.js52
-rw-r--r--jstests/core/insert_illegal_doc.js2
-rw-r--r--jstests/core/js3.js8
-rw-r--r--jstests/core/list_indexes.js16
-rw-r--r--jstests/core/list_indexes_invalid.js2
-rw-r--r--jstests/core/minmax.js12
-rw-r--r--jstests/core/mr_multikey_deduping.js4
-rw-r--r--jstests/core/mr_sort.js2
-rw-r--r--jstests/core/multi.js2
-rw-r--r--jstests/core/multi2.js4
-rw-r--r--jstests/core/multikey_geonear.js8
-rw-r--r--jstests/core/ne1.js2
-rw-r--r--jstests/core/ne2.js2
-rw-r--r--jstests/core/nestedarr1.js2
-rw-r--r--jstests/core/nestedobj1.js2
-rw-r--r--jstests/core/nin.js2
-rw-r--r--jstests/core/not1.js2
-rw-r--r--jstests/core/not2.js2
-rw-r--r--jstests/core/not3.js2
-rw-r--r--jstests/core/notablescan.js2
-rw-r--r--jstests/core/numberlong2.js2
-rw-r--r--jstests/core/numberlong4.js2
-rw-r--r--jstests/core/or1.js6
-rw-r--r--jstests/core/or2.js8
-rw-r--r--jstests/core/or3.js8
-rw-r--r--jstests/core/or4.js4
-rw-r--r--jstests/core/or5.js14
-rw-r--r--jstests/core/or6.js4
-rw-r--r--jstests/core/or7.js2
-rw-r--r--jstests/core/or8.js6
-rw-r--r--jstests/core/or9.js2
-rw-r--r--jstests/core/or_inexact.js52
-rw-r--r--jstests/core/ora.js2
-rw-r--r--jstests/core/orb.js4
-rw-r--r--jstests/core/orc.js2
-rw-r--r--jstests/core/ord.js4
-rw-r--r--jstests/core/ore.js4
-rw-r--r--jstests/core/org.js4
-rw-r--r--jstests/core/orh.js4
-rw-r--r--jstests/core/orj.js16
-rw-r--r--jstests/core/ork.js2
-rw-r--r--jstests/core/oro.js2
-rw-r--r--jstests/core/orp.js12
-rw-r--r--jstests/core/profile_list_indexes.js2
-rw-r--r--jstests/core/proj_key1.js2
-rw-r--r--jstests/core/queryoptimizera.js2
-rw-r--r--jstests/core/record_store_count.js4
-rw-r--r--jstests/core/regex3.js6
-rw-r--r--jstests/core/regex4.js2
-rw-r--r--jstests/core/regex5.js2
-rw-r--r--jstests/core/regex6.js2
-rw-r--r--jstests/core/regex7.js2
-rw-r--r--jstests/core/regex8.js2
-rw-r--r--jstests/core/regex_embed1.js2
-rw-r--r--jstests/core/regexa.js2
-rw-r--r--jstests/core/regexc.js6
-rw-r--r--jstests/core/remove.js2
-rw-r--r--jstests/core/remove2.js4
-rw-r--r--jstests/core/remove6.js2
-rw-r--r--jstests/core/remove7.js2
-rw-r--r--jstests/core/remove9.js2
-rw-r--r--jstests/core/removea.js2
-rw-r--r--jstests/core/removeb.js2
-rw-r--r--jstests/core/removec.js2
-rw-r--r--jstests/core/rename.js4
-rw-r--r--jstests/core/rename4.js2
-rw-r--r--jstests/core/rename5.js2
-rw-r--r--jstests/core/rename6.js2
-rw-r--r--jstests/core/rename7.js4
-rw-r--r--jstests/core/return_key.js4
-rw-r--r--jstests/core/server14747.js4
-rw-r--r--jstests/core/server14753.js4
-rw-r--r--jstests/core/server9547.js2
-rw-r--r--jstests/core/set_type_change.js2
-rw-r--r--jstests/core/show_record_id.js2
-rw-r--r--jstests/core/skip1.js2
-rw-r--r--jstests/core/sort1.js4
-rw-r--r--jstests/core/sort10.js6
-rw-r--r--jstests/core/sort2.js4
-rw-r--r--jstests/core/sort4.js4
-rw-r--r--jstests/core/sort5.js4
-rw-r--r--jstests/core/sort6.js4
-rw-r--r--jstests/core/sort8.js4
-rw-r--r--jstests/core/sort_numeric.js2
-rw-r--r--jstests/core/sortb.js2
-rw-r--r--jstests/core/sortd.js8
-rw-r--r--jstests/core/sortf.js4
-rw-r--r--jstests/core/sortg.js6
-rw-r--r--jstests/core/sorth.js2
-rw-r--r--jstests/core/sorti.js2
-rw-r--r--jstests/core/sortj.js2
-rw-r--r--jstests/core/sortk.js6
-rw-r--r--jstests/core/splitvector.js38
-rw-r--r--jstests/core/stages_and_hash.js6
-rw-r--r--jstests/core/stages_and_sorted.js6
-rw-r--r--jstests/core/stages_fetch.js2
-rw-r--r--jstests/core/stages_ixscan.js4
-rw-r--r--jstests/core/stages_limit_skip.js2
-rw-r--r--jstests/core/stages_mergesort.js4
-rw-r--r--jstests/core/stages_or.js6
-rw-r--r--jstests/core/stages_sort.js2
-rw-r--r--jstests/core/stages_text.js2
-rw-r--r--jstests/core/type1.js2
-rw-r--r--jstests/core/type2.js2
-rw-r--r--jstests/core/type3.js2
-rw-r--r--jstests/core/uniqueness.js4
-rw-r--r--jstests/core/update2.js2
-rw-r--r--jstests/core/update5.js2
-rw-r--r--jstests/core/update7.js8
-rw-r--r--jstests/core/update_arraymatch4.js2
-rw-r--r--jstests/core/update_arraymatch5.js2
-rw-r--r--jstests/core/update_arraymatch6.js2
-rw-r--r--jstests/core/update_arraymatch7.js2
-rw-r--r--jstests/core/update_arraymatch8.js30
-rw-r--r--jstests/core/update_multi3.js2
-rw-r--r--jstests/core/update_multi4.js2
-rw-r--r--jstests/core/update_setOnInsert.js2
-rw-r--r--jstests/core/useindexonobjgtlt.js2
-rw-r--r--jstests/gle/create_index_gle.js2
-rw-r--r--jstests/libs/geo_near_random.js4
-rw-r--r--jstests/libs/write_concern_util.js2
-rw-r--r--jstests/multiVersion/libs/data_generators.js2
-rw-r--r--jstests/multiVersion/libs/verify_collection_data.js6
-rw-r--r--jstests/noPassthrough/current_op_reports_validation_io.js2
-rw-r--r--jstests/noPassthrough/document_count_functions.js2
-rw-r--r--jstests/noPassthrough/filemd5_kill_during_yield.js2
-rw-r--r--jstests/noPassthrough/geo_full.js6
-rw-r--r--jstests/noPassthrough/geo_mnypts_plus_fields.js2
-rw-r--r--jstests/noPassthrough/index_partial_no_explain_cmds.js2
-rw-r--r--jstests/noPassthrough/indexbg1.js2
-rw-r--r--jstests/noPassthrough/indexbg2.js2
-rw-r--r--jstests/noPassthrough/indexbg_drop.js4
-rw-r--r--jstests/noPassthrough/libs/backup_restore.js2
-rw-r--r--jstests/noPassthrough/lookup_with_limit_sharded.js2
-rw-r--r--jstests/noPassthrough/ttl_capped.js2
-rw-r--r--jstests/noPassthrough/ttl_hidden_index.js2
-rw-r--r--jstests/noPassthrough/ttl_monitor_does_not_unregister_index_during_collection_creation.js6
-rw-r--r--jstests/noPassthrough/ttl_partial_index.js2
-rw-r--r--jstests/noPassthrough/ttl_resharding_collection.js2
-rw-r--r--jstests/noPassthrough/update_server-5552.js2
-rw-r--r--jstests/noPassthroughWithMongod/apply_ops_errors.js4
-rw-r--r--jstests/noPassthroughWithMongod/background.js2
-rw-r--r--jstests/noPassthroughWithMongod/bulk_api_limits.js2
-rw-r--r--jstests/noPassthroughWithMongod/capped4.js2
-rw-r--r--jstests/noPassthroughWithMongod/dup_bgindex.js4
-rw-r--r--jstests/noPassthroughWithMongod/explain1.js2
-rw-r--r--jstests/noPassthroughWithMongod/explain2.js2
-rw-r--r--jstests/noPassthroughWithMongod/explain3.js2
-rw-r--r--jstests/noPassthroughWithMongod/external_sort_text_agg.js2
-rw-r--r--jstests/noPassthroughWithMongod/geo_axis_aligned.js4
-rw-r--r--jstests/noPassthroughWithMongod/geo_mnypts.js2
-rw-r--r--jstests/noPassthroughWithMongod/geo_polygon.js2
-rw-r--r--jstests/noPassthroughWithMongod/huge_multikey_index.js4
-rw-r--r--jstests/noPassthroughWithMongod/index_check10.js2
-rw-r--r--jstests/noPassthroughWithMongod/index_check9.js2
-rw-r--r--jstests/noPassthroughWithMongod/indexbg_interrupts.js2
-rw-r--r--jstests/noPassthroughWithMongod/recstore.js8
-rw-r--r--jstests/noPassthroughWithMongod/renameWithWCE.js4
-rw-r--r--jstests/noPassthroughWithMongod/temp_namespace.js4
-rw-r--r--jstests/noPassthroughWithMongod/ttl1.js4
-rw-r--r--jstests/noPassthroughWithMongod/ttl_repl.js2
-rw-r--r--jstests/noPassthroughWithMongod/ttl_repl_maintenance.js2
-rw-r--r--jstests/noPassthroughWithMongod/ttl_repl_secondary_disabled.js2
-rw-r--r--jstests/noPassthroughWithMongod/ttl_sharded.js2
-rw-r--r--jstests/noPassthroughWithMongod/validate_command.js4
-rw-r--r--jstests/parallel/insert.js2
-rw-r--r--jstests/parallel/manyclients.js2
-rw-r--r--jstests/parallel/update_serializability1.js4
-rw-r--r--jstests/parallel/update_serializability2.js4
-rw-r--r--jstests/perf/compact_speed_test.js6
-rw-r--r--jstests/perf/find1.js2
-rw-r--r--jstests/perf/index1.js4
-rw-r--r--jstests/perf/remove1.js2
-rw-r--r--jstests/replsets/apply_ops_create_indexes.js48
-rw-r--r--jstests/replsets/background_index.js2
-rw-r--r--jstests/replsets/buildindexes.js2
-rw-r--r--jstests/replsets/bulk_api_wc.js2
-rw-r--r--jstests/replsets/drop_collections_two_phase_rename_drop_target.js4
-rw-r--r--jstests/replsets/initial_sync4.js2
-rw-r--r--jstests/replsets/initial_sync_ambiguous_index.js2
-rw-r--r--jstests/replsets/initial_sync_move_forward.js2
-rw-r--r--jstests/replsets/reindex.js4
-rw-r--r--jstests/replsets/replset1.js2
-rw-r--r--jstests/replsets/temp_namespace.js4
-rw-r--r--jstests/sharding/addshard1.js2
-rw-r--r--jstests/sharding/array_shard_key.js6
-rw-r--r--jstests/sharding/bulk_insert.js4
-rw-r--r--jstests/sharding/coll_epoch_test1.js2
-rw-r--r--jstests/sharding/covered_shard_key_indexes.js22
-rw-r--r--jstests/sharding/create_idx_empty_primary.js2
-rw-r--r--jstests/sharding/delete_during_migrate.js2
-rw-r--r--jstests/sharding/drop_indexes_with_stale_config_error.js2
-rw-r--r--jstests/sharding/features2.js4
-rw-r--r--jstests/sharding/fts_score_sort_sharded.js4
-rw-r--r--jstests/sharding/hash_shard_non_empty.js2
-rw-r--r--jstests/sharding/hash_shard_unique_compound.js4
-rw-r--r--jstests/sharding/index1.js56
-rw-r--r--jstests/sharding/key_many.js2
-rw-r--r--jstests/sharding/limit_push.js2
-rw-r--r--jstests/sharding/mongos_validate_writes.js10
-rw-r--r--jstests/sharding/move_chunk_missing_idx.js2
-rw-r--r--jstests/sharding/move_chunk_wc.js2
-rw-r--r--jstests/sharding/prefix_shard_key.js10
-rw-r--r--jstests/sharding/printShardingStatus.js2
-rw-r--r--jstests/sharding/query/explain_cmd.js8
-rw-r--r--jstests/sharding/query/explain_exec_stats_on_shards.js2
-rw-r--r--jstests/sharding/query/explain_find_and_modify_sharded.js2
-rw-r--r--jstests/sharding/query/find_getmore_cmd.js2
-rw-r--r--jstests/sharding/query/geo_near_sharded.js2
-rw-r--r--jstests/sharding/read_pref_cmd.js2
-rw-r--r--jstests/sharding/refine_shardkey_config_cache_refresh.js2
-rw-r--r--jstests/sharding/shard1.js2
-rw-r--r--jstests/sharding/shard7.js2
-rw-r--r--jstests/sharding/shard_insert_getlasterror_w2.js2
-rw-r--r--jstests/sharding/sharding_rs1.js2
-rw-r--r--jstests/sharding/sharding_rs2.js2
-rw-r--r--jstests/sharding/stats.js2
-rw-r--r--jstests/sharding/trace_missing_docs_test.js2
-rw-r--r--jstests/slow1/conc_update.js2
-rw-r--r--src/mongo/shell/collection.js20
543 files changed, 1232 insertions, 1164 deletions
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_causal_consistency.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_causal_consistency.yml
index 5949fb48075..0f7946d8670 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_causal_consistency.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_causal_consistency.yml
@@ -61,7 +61,7 @@ selector:
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_causal_consistency_and_balancer.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_causal_consistency_and_balancer.yml
index 40ae7b4ac69..9bb04c112c5 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_causal_consistency_and_balancer.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_causal_consistency_and_balancer.yml
@@ -64,7 +64,7 @@ selector:
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_kill_primary_with_balancer.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_kill_primary_with_balancer.yml
index faa1dce843e..b6dd60cf5bc 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_kill_primary_with_balancer.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_kill_primary_with_balancer.yml
@@ -71,7 +71,7 @@ selector:
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# The WTWriteConflictException failpoint is not supported on mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_local_read_write_multi_stmt_txn.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_local_read_write_multi_stmt_txn.yml
index c4044f40d88..f2f0e5dc637 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_local_read_write_multi_stmt_txn.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_local_read_write_multi_stmt_txn.yml
@@ -61,7 +61,7 @@ selector:
# can cause OOM kills on test hosts
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_local_read_write_multi_stmt_txn_with_balancer.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_local_read_write_multi_stmt_txn_with_balancer.yml
index ec96f2431d9..33c364f97dd 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_local_read_write_multi_stmt_txn_with_balancer.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_local_read_write_multi_stmt_txn_with_balancer.yml
@@ -61,7 +61,7 @@ selector:
# can cause OOM kills on test hosts
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn.yml
index eb6a8f754f4..3ba770e70a6 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn.yml
@@ -61,7 +61,7 @@ selector:
# can cause OOM kills on test hosts
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_kill_primary.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_kill_primary.yml
index 8aa0ee3784d..f1a689fa316 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_kill_primary.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_kill_primary.yml
@@ -77,7 +77,7 @@ selector:
# can cause OOM kills on test hosts
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_terminate_primary.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_terminate_primary.yml
index 6c8c02121ae..dd6c821c646 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_terminate_primary.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_terminate_primary.yml
@@ -77,7 +77,7 @@ selector:
# can cause OOM kills on test hosts
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_with_balancer.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_with_balancer.yml
index 294342b192c..874de8baaee 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_with_balancer.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_with_balancer.yml
@@ -61,7 +61,7 @@ selector:
# can cause OOM kills on test hosts
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_with_stepdowns.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_with_stepdowns.yml
index 885f6c865de..d916b3ce65e 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_with_stepdowns.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_multi_stmt_txn_with_stepdowns.yml
@@ -66,7 +66,7 @@ selector:
# can cause OOM kills on test hosts
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_replication.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_replication.yml
index 71bf7634897..a4077faed3f 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_replication.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_replication.yml
@@ -60,7 +60,7 @@ selector:
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_replication_with_balancer.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_replication_with_balancer.yml
index 8a8c863d129..2a53ce35f21 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_replication_with_balancer.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_replication_with_balancer.yml
@@ -62,7 +62,7 @@ selector:
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# reIndex is not supported in mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_terminate_primary_with_balancer.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_terminate_primary_with_balancer.yml
index fa6c78b2ee5..76fb5a6f270 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_terminate_primary_with_balancer.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_terminate_primary_with_balancer.yml
@@ -71,7 +71,7 @@ selector:
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# The WTWriteConflictException failpoint is not supported on mongos.
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_with_stepdowns.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_with_stepdowns.yml
index a65c5d559c1..ce3749db4bd 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_with_stepdowns.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_with_stepdowns.yml
@@ -68,7 +68,7 @@ selector:
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# our .remove(query, {justOne: true}) calls lack shard keys
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded_with_stepdowns_and_balancer.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded_with_stepdowns_and_balancer.yml
index 413fa17a469..a839376f964 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded_with_stepdowns_and_balancer.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded_with_stepdowns_and_balancer.yml
@@ -71,7 +71,7 @@ selector:
- jstests/concurrency/fsm_workloads/findAndModify_update_grow.js
- # cannot createIndex after dropDatabase without sharding first
+ # cannot ensureIndex after dropDatabase without sharding first
- jstests/concurrency/fsm_workloads/plan_cache_drop_database.js
# our .remove(query, {justOne: true}) calls lack shard keys
diff --git a/jstests/aggregation/bugs/server12015.js b/jstests/aggregation/bugs/server12015.js
index bae114f2417..2027b6d9ff5 100644
--- a/jstests/aggregation/bugs/server12015.js
+++ b/jstests/aggregation/bugs/server12015.js
@@ -36,7 +36,7 @@ function assertResultsMatch(pipeline, ignoreSortOrder) {
pipeline = [{$match: {a: {$gte: 0}}}].concat(pipeline);
// Once with an index.
- assert.commandWorked(coll.createIndex(indexSpec));
+ assert.commandWorked(coll.ensureIndex(indexSpec));
var resultsWithIndex = coll.aggregate(pipeline).toArray();
// Again without an index.
diff --git a/jstests/aggregation/bugs/server13715.js b/jstests/aggregation/bugs/server13715.js
index f099480f935..27482cc1c46 100644
--- a/jstests/aggregation/bugs/server13715.js
+++ b/jstests/aggregation/bugs/server13715.js
@@ -12,7 +12,7 @@ assert.eq(1, cursor.next()["_id"]);
assert.eq(0, cursor.next()["_id"]);
// Repeat the test with an index.
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
cursor = t.aggregate([{$match: {$or: [{name: "red"}, {name: "blue"}]}}, {$sort: {value: 1}}]);
assert.eq(1, cursor.next()["_id"]);
diff --git a/jstests/aggregation/bugs/server14969.js b/jstests/aggregation/bugs/server14969.js
index 15fd423f44a..0da44f18c6d 100644
--- a/jstests/aggregation/bugs/server14969.js
+++ b/jstests/aggregation/bugs/server14969.js
@@ -11,7 +11,7 @@ var longString = new Array(1024 * 1024).join('x');
for (var i = 0; i < 100; ++i) {
assert.commandWorked(coll.insert({a: 1, bigField: longString}));
}
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
// Create pipeline that uses index "a", with a small initial batch size.
var cursor = coll.aggregate([{$match: {a: 1}}], {cursor: {batchSize: docsPerBatch}});
diff --git a/jstests/aggregation/bugs/server22093.js b/jstests/aggregation/bugs/server22093.js
index b63cfd7aabb..e3a3268c048 100644
--- a/jstests/aggregation/bugs/server22093.js
+++ b/jstests/aggregation/bugs/server22093.js
@@ -26,7 +26,7 @@ for (var i = 0; i < 3; i++) {
}
}
-coll.createIndex({foo: 1});
+coll.ensureIndex({foo: 1});
var simpleGroup = coll.aggregate([{$group: {_id: null, count: {$sum: 1}}}]).toArray();
diff --git a/jstests/aggregation/bugs/server3253.js b/jstests/aggregation/bugs/server3253.js
index e3c9b4847c1..ac7ed42eed0 100644
--- a/jstests/aggregation/bugs/server3253.js
+++ b/jstests/aggregation/bugs/server3253.js
@@ -66,7 +66,7 @@ test(input,
// test with indexes
assert.eq(output.getIndexes().length, 1);
-output.createIndex({a: 1});
+output.ensureIndex({a: 1});
assert.eq(output.getIndexes().length, 2);
test(input,
[{$project: {a: {$multiply: ['$_id', '$_id']}}}],
@@ -77,12 +77,12 @@ test(input, [{$match: {_id: 11}}], []);
assert.eq(output.getIndexes().length, 2);
// test with geo index
-output.createIndex({b: "2d"});
+output.ensureIndex({b: "2d"});
assert.eq(output.getIndexes().length, 3);
test(input, [{$project: {b: "$_id"}}], [{_id: 1, b: 1}, {_id: 2, b: 2}, {_id: 3, b: 3}]);
// test with full text index
-output.createIndex({c: "text"});
+output.ensureIndex({c: "text"});
assert.eq(output.getIndexes().length, 4);
test(input, [{$project: {c: {$concat: ["hello there ", "_id"]}}}], [
{_id: 1, c: "hello there _id"},
diff --git a/jstests/aggregation/bugs/server3832.js b/jstests/aggregation/bugs/server3832.js
index 82b38ab3604..b2c59ccd244 100644
--- a/jstests/aggregation/bugs/server3832.js
+++ b/jstests/aggregation/bugs/server3832.js
@@ -25,7 +25,7 @@ var a3 = s3832.aggregate({$match: {b: "baz"}}, {$sort: {a: 1}});
assert.eq(a3.toArray(), a1result, 's3832.a3 failed');
-db.s3832.createIndex({b: 1}, {name: "s3832_b"});
+db.s3832.ensureIndex({b: 1}, {name: "s3832_b"});
var a4 = s3832.aggregate({$match: {b: "baz"}});
@@ -41,7 +41,7 @@ assert.eq(a6.toArray(), a1result, 's3832.a6 failed');
var dropb = db.s3832.dropIndex("s3832_b");
-db.s3832.createIndex({a: 1}, {name: "s3832_a"});
+db.s3832.ensureIndex({a: 1}, {name: "s3832_a"});
var a7 = s3832.aggregate({$match: {b: "baz"}});
diff --git a/jstests/aggregation/bugs/server6531.js b/jstests/aggregation/bugs/server6531.js
index 46f09a0f379..cd2faae0eb7 100644
--- a/jstests/aggregation/bugs/server6531.js
+++ b/jstests/aggregation/bugs/server6531.js
@@ -23,9 +23,9 @@ function test(variant) {
test("no index");
-c.createIndex({loc: "2d"});
+c.ensureIndex({loc: "2d"});
test("2d index");
c.dropIndex({loc: "2d"});
-c.createIndex({loc: "2dsphere"});
+c.ensureIndex({loc: "2dsphere"});
test("2dsphere index");
diff --git a/jstests/aggregation/bugs/server7781.js b/jstests/aggregation/bugs/server7781.js
index 77f8bbc6866..586099df79f 100644
--- a/jstests/aggregation/bugs/server7781.js
+++ b/jstests/aggregation/bugs/server7781.js
@@ -67,7 +67,7 @@ function test(db, indexType) {
assert.eq(db[coll].count(), numPts);
- db[coll].createIndex({loc: indexType});
+ db[coll].ensureIndex({loc: indexType});
// Test $geoNear with spherical coordinates.
testGeoNearStageOutput({
diff --git a/jstests/aggregation/bugs/sort_arrays.js b/jstests/aggregation/bugs/sort_arrays.js
index 488b0300381..a82837dfb70 100644
--- a/jstests/aggregation/bugs/sort_arrays.js
+++ b/jstests/aggregation/bugs/sort_arrays.js
@@ -11,7 +11,7 @@ const expectedOrder = [{_id: 4, a: [2, 1]}, {_id: 2, a: [2, 3]}, {_id: 3, a: [2,
assert.eq(coll.aggregate([{$sort: {a: 1, _id: 1}}]).toArray(), expectedOrder);
assert.eq(coll.find().sort({a: 1, _id: 1}).toArray(), expectedOrder);
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
assert.eq(coll.aggregate([{$sort: {a: 1, _id: 1}}]).toArray(), expectedOrder);
assert.eq(coll.find().sort({a: 1, _id: 1}).toArray(), expectedOrder);
}());
diff --git a/jstests/auth/basic_role_auth.js b/jstests/auth/basic_role_auth.js
index b86f61dba9d..ff487bebbd9 100644
--- a/jstests/auth/basic_role_auth.js
+++ b/jstests/auth/basic_role_auth.js
@@ -129,7 +129,7 @@ var testOps = function(db, allowedActions) {
});
checkErr(allowedActions.hasOwnProperty('index_w'), function() {
- var res = db.user.createIndex({x: 1});
+ var res = db.user.ensureIndex({x: 1});
if (res.code == 13) { // Unauthorized
throw Error("unauthorized currentOp");
}
diff --git a/jstests/auth/lib/commands_lib.js b/jstests/auth/lib/commands_lib.js
index 8015d8dc143..80a1a6d99a6 100644
--- a/jstests/auth/lib/commands_lib.js
+++ b/jstests/auth/lib/commands_lib.js
@@ -3481,7 +3481,7 @@ var authCommandsLib = {
setup: function(db) {
db.fs.chunks.drop();
assert.writeOK(db.fs.chunks.insert({files_id: 1, n: 0, data: new BinData(0, "test")}));
- assert.commandWorked(db.fs.chunks.createIndex({files_id: 1, n: 1}));
+ assert.commandWorked(db.fs.chunks.ensureIndex({files_id: 1, n: 1}));
},
teardown: function(db) {
db.fs.chunks.drop();
diff --git a/jstests/auth/readIndex.js b/jstests/auth/readIndex.js
index 53c5d63ecba..27fd03a637f 100644
--- a/jstests/auth/readIndex.js
+++ b/jstests/auth/readIndex.js
@@ -12,7 +12,7 @@ testDB.createUser({user: 'dbAdmin', pwd: 'password', roles: ['dbAdmin']});
adminDB.logout();
testDB.auth('dbAdmin', 'password');
-testDB.foo.createIndex({a: 1}, {name: indexName});
+testDB.foo.ensureIndex({a: 1}, {name: indexName});
assert.eq(2, testDB.foo.getIndexes().length); // index on 'a' plus default _id index
var indexList = testDB.foo.getIndexes().filter(function(idx) {
return idx.name === indexName;
diff --git a/jstests/concurrency/fsm_example_inheritance.js b/jstests/concurrency/fsm_example_inheritance.js
index dd6364b2d87..8c45525d7e3 100644
--- a/jstests/concurrency/fsm_example_inheritance.js
+++ b/jstests/concurrency/fsm_example_inheritance.js
@@ -16,7 +16,7 @@ var $config = extendWorkload($config, function($config, $super) {
// method on $super.
$super.setup.apply(this, arguments);
- db[collName].createIndex({exampleIndexedField: 1});
+ db[collName].ensureIndex({exampleIndexedField: 1});
};
return $config;
diff --git a/jstests/concurrency/fsm_workloads/agg_out.js b/jstests/concurrency/fsm_workloads/agg_out.js
index 6c1d720558f..200ee7917fd 100644
--- a/jstests/concurrency/fsm_workloads/agg_out.js
+++ b/jstests/concurrency/fsm_workloads/agg_out.js
@@ -38,7 +38,7 @@ var $config = extendWorkload($config, function($config, $super) {
$config.transitions = {
query: {
query: 0.68,
- createIndexes: 0.1,
+ ensureIndexes: 0.1,
dropIndex: 0.1,
collMod: 0.1,
// Converting the target collection to a capped collection or a sharded collection will
@@ -47,7 +47,7 @@ var $config = extendWorkload($config, function($config, $super) {
convertToCapped: 0.01,
shardCollection: 0.01,
},
- createIndexes: {query: 1},
+ ensureIndexes: {query: 1},
dropIndex: {query: 1},
collMod: {query: 1},
convertToCapped: {query: 1},
@@ -85,9 +85,9 @@ var $config = extendWorkload($config, function($config, $super) {
* Ensures all the indexes exist. This will have no affect unless some thread has already
* dropped an index.
*/
- $config.states.createIndexes = function createIndexes(db, unusedCollName) {
+ $config.states.ensureIndexes = function ensureIndexes(db, unusedCollName) {
for (var i = 0; i < this.indexSpecs; ++i) {
- assertWhenOwnDB.commandWorked(db[this.outputCollName].createIndex(this.indexSpecs[i]));
+ assertWhenOwnDB.commandWorked(db[this.outputCollName].ensureIndex(this.indexSpecs[i]));
}
};
diff --git a/jstests/concurrency/fsm_workloads/collmod.js b/jstests/concurrency/fsm_workloads/collmod.js
index fdb93bfc65a..095602b43af 100644
--- a/jstests/concurrency/fsm_workloads/collmod.js
+++ b/jstests/concurrency/fsm_workloads/collmod.js
@@ -48,7 +48,7 @@ var $config = (function() {
assertAlways.eq(this.numDocs, res.nInserted);
// create TTL index
- res = db[this.threadCollName].createIndex({createdAt: 1}, {expireAfterSeconds: 3600});
+ res = db[this.threadCollName].ensureIndex({createdAt: 1}, {expireAfterSeconds: 3600});
assertAlways.commandWorked(res);
}
diff --git a/jstests/concurrency/fsm_workloads/compact.js b/jstests/concurrency/fsm_workloads/compact.js
index 558cd5b5fd4..cae5571f733 100644
--- a/jstests/concurrency/fsm_workloads/compact.js
+++ b/jstests/concurrency/fsm_workloads/compact.js
@@ -37,15 +37,15 @@ var $config = (function() {
function createIndexes(db, collName) {
// The number of indexes created here is also stored in data.nIndexes
- var aResult = db[collName].createIndex({a: 1});
+ var aResult = db[collName].ensureIndex({a: 1});
assertWorkedHandleTxnErrors(aResult, ErrorCodes.IndexBuildAlreadyInProgress);
- var bResult = db[collName].createIndex({b: 1});
+ var bResult = db[collName].ensureIndex({b: 1});
assertWorkedHandleTxnErrors(bResult, ErrorCodes.IndexBuildAlreadyInProgress);
- var cResult = db[collName].createIndex({c: 1});
+ var cResult = db[collName].ensureIndex({c: 1});
assertWorkedHandleTxnErrors(cResult, ErrorCodes.IndexBuildAlreadyInProgress);
}
diff --git a/jstests/concurrency/fsm_workloads/convert_to_capped_collection_index.js b/jstests/concurrency/fsm_workloads/convert_to_capped_collection_index.js
index be4414f642d..70c2fbc3b4c 100644
--- a/jstests/concurrency/fsm_workloads/convert_to_capped_collection_index.js
+++ b/jstests/concurrency/fsm_workloads/convert_to_capped_collection_index.js
@@ -20,7 +20,7 @@ load('jstests/concurrency/fsm_workloads/convert_to_capped_collection.js'); // f
var $config = extendWorkload($config, function($config, $super) {
$config.states.convertToCapped = function convertToCapped(db, collName) {
- assertWhenOwnDB.commandWorked(db[this.threadCollName].createIndex({i: 1, rand: 1}));
+ assertWhenOwnDB.commandWorked(db[this.threadCollName].ensureIndex({i: 1, rand: 1}));
assertWhenOwnDB.eq(2, db[this.threadCollName].getIndexes().length);
$super.states.convertToCapped.apply(this, arguments);
};
diff --git a/jstests/concurrency/fsm_workloads/count_indexed.js b/jstests/concurrency/fsm_workloads/count_indexed.js
index 9887d1a113e..b8041d5f91a 100644
--- a/jstests/concurrency/fsm_workloads/count_indexed.js
+++ b/jstests/concurrency/fsm_workloads/count_indexed.js
@@ -25,7 +25,7 @@ var $config = extendWorkload($config, function($config, $super) {
$config.states.init = function init(db, collName) {
this.threadCollName = this.prefix + '_' + this.tid;
$super.states.init.apply(this, arguments);
- assertAlways.commandWorked(db[this.threadCollName].createIndex({tid: 1, i: 1}));
+ assertAlways.commandWorked(db[this.threadCollName].ensureIndex({tid: 1, i: 1}));
};
return $config;
diff --git a/jstests/concurrency/fsm_workloads/create_index_background.js b/jstests/concurrency/fsm_workloads/create_index_background.js
index 2a55b307086..e183a33e36d 100644
--- a/jstests/concurrency/fsm_workloads/create_index_background.js
+++ b/jstests/concurrency/fsm_workloads/create_index_background.js
@@ -202,7 +202,7 @@ var $config = (function() {
var nSetupDocs = this.nDocumentsToSeed * 200;
var coll = db[collName];
- var res = coll.createIndex({tid: 1});
+ var res = coll.ensureIndex({tid: 1});
assertAlways.commandWorked(res, tojson(res));
var bulk = coll.initializeUnorderedBulkOp();
diff --git a/jstests/concurrency/fsm_workloads/distinct.js b/jstests/concurrency/fsm_workloads/distinct.js
index 2c56372c7d7..2832ea215d3 100644
--- a/jstests/concurrency/fsm_workloads/distinct.js
+++ b/jstests/concurrency/fsm_workloads/distinct.js
@@ -21,7 +21,7 @@ var $config = (function() {
var res = bulk.execute();
assertAlways.commandWorked(res);
assertAlways.eq(this.numDocs, res.nInserted);
- assertAlways.commandWorked(db[this.threadCollName].createIndex({i: 1}));
+ assertAlways.commandWorked(db[this.threadCollName].ensureIndex({i: 1}));
}
function distinct(db, collName) {
diff --git a/jstests/concurrency/fsm_workloads/explain.js b/jstests/concurrency/fsm_workloads/explain.js
index ca20aa4b8c9..b4943a23300 100644
--- a/jstests/concurrency/fsm_workloads/explain.js
+++ b/jstests/concurrency/fsm_workloads/explain.js
@@ -26,7 +26,7 @@ var $config = (function() {
};
function setup(db, collName, cluster) {
- assertAlways.commandWorked(db[collName].createIndex({j: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({j: 1}));
}
var states = (function() {
diff --git a/jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js b/jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js
index e902ceb1959..6c49a7cc249 100644
--- a/jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js
+++ b/jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js
@@ -97,8 +97,8 @@ var $config = (function() {
assertAlways.commandWorked(res);
assertAlways.eq(this.numDocs, res.nInserted);
- this.getIndexSpecs().forEach(function createIndex(indexSpec) {
- assertAlways.commandWorked(db[collName].createIndex(indexSpec));
+ this.getIndexSpecs().forEach(function ensureIndex(indexSpec) {
+ assertAlways.commandWorked(db[collName].ensureIndex(indexSpec));
});
}
diff --git a/jstests/concurrency/fsm_workloads/findAndModify_update.js b/jstests/concurrency/fsm_workloads/findAndModify_update.js
index e97281b5a8a..9035e6f472f 100644
--- a/jstests/concurrency/fsm_workloads/findAndModify_update.js
+++ b/jstests/concurrency/fsm_workloads/findAndModify_update.js
@@ -83,7 +83,7 @@ var $config = (function() {
};
function setup(db, collName, cluster) {
- var res = db[collName].createIndex({tid: 1, value: 1});
+ var res = db[collName].ensureIndex({tid: 1, value: 1});
assertAlways.commandWorked(res);
}
diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_text.js b/jstests/concurrency/fsm_workloads/indexed_insert_text.js
index cb467a03a4a..beea5501dd7 100644
--- a/jstests/concurrency/fsm_workloads/indexed_insert_text.js
+++ b/jstests/concurrency/fsm_workloads/indexed_insert_text.js
@@ -37,7 +37,7 @@ var $config = (function() {
var ixSpec = {};
ixSpec[this.indexedField] = 'text';
// Only allowed to create one text index, other tests may create one.
- assertWhenOwnColl.commandWorked(db[collName].createIndex(ixSpec));
+ assertWhenOwnColl.commandWorked(db[collName].ensureIndex(ixSpec));
}
var text = [
diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_ttl.js b/jstests/concurrency/fsm_workloads/indexed_insert_ttl.js
index b0d999076e7..5a54c673cac 100644
--- a/jstests/concurrency/fsm_workloads/indexed_insert_ttl.js
+++ b/jstests/concurrency/fsm_workloads/indexed_insert_ttl.js
@@ -27,7 +27,7 @@ var $config = (function() {
var transitions = {init: {insert: 1}, insert: {insert: 1}};
function setup(db, collName, cluster) {
- var res = db[collName].createIndex({indexed_insert_ttl: 1},
+ var res = db[collName].ensureIndex({indexed_insert_ttl: 1},
{expireAfterSeconds: this.ttlSeconds});
assertAlways.commandWorked(res);
}
diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_where.js b/jstests/concurrency/fsm_workloads/indexed_insert_where.js
index 4cd751c1e1c..5233c6c3e48 100644
--- a/jstests/concurrency/fsm_workloads/indexed_insert_where.js
+++ b/jstests/concurrency/fsm_workloads/indexed_insert_where.js
@@ -42,7 +42,7 @@ var $config = (function() {
var transitions = {insert: {insert: 0.2, query: 0.8}, query: {insert: 0.8, query: 0.2}};
var setup = function setup(db, collName, cluster) {
- assertAlways.commandWorked(db[collName].createIndex({tid: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({tid: 1}));
};
return {
diff --git a/jstests/concurrency/fsm_workloads/list_indexes.js b/jstests/concurrency/fsm_workloads/list_indexes.js
index 687f871a378..ba5549e1e68 100644
--- a/jstests/concurrency/fsm_workloads/list_indexes.js
+++ b/jstests/concurrency/fsm_workloads/list_indexes.js
@@ -15,7 +15,7 @@ var $config = (function() {
assertWhenOwnColl.commandWorked(db[collName].dropIndex(spec));
sleep(100);
- assertWhenOwnColl.commandWorked(db[collName].createIndex(spec));
+ assertWhenOwnColl.commandWorked(db[collName].ensureIndex(spec));
}
// List indexes, using a batchSize of 2 to ensure getmores happen.
@@ -38,7 +38,7 @@ var $config = (function() {
for (var i = 0; i < this.threadCount; ++i) {
var spec = {};
spec['foo' + i] = 1;
- assertAlways.commandWorked(db[collName].createIndex(spec));
+ assertAlways.commandWorked(db[collName].ensureIndex(spec));
}
}
diff --git a/jstests/concurrency/fsm_workloads/update_array.js b/jstests/concurrency/fsm_workloads/update_array.js
index 99e31e735a3..457392279fd 100644
--- a/jstests/concurrency/fsm_workloads/update_array.js
+++ b/jstests/concurrency/fsm_workloads/update_array.js
@@ -109,7 +109,7 @@ var $config = (function() {
function setup(db, collName, cluster) {
// index on 'arr', the field being updated
- assertAlways.commandWorked(db[collName].createIndex({arr: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({arr: 1}));
for (var i = 0; i < this.numDocs; ++i) {
var res = db[collName].insert({_id: i, arr: []});
assertWhenOwnColl.commandWorked(res);
diff --git a/jstests/concurrency/fsm_workloads/update_check_index.js b/jstests/concurrency/fsm_workloads/update_check_index.js
index 71b8d32dfae..8cfa98f6c84 100644
--- a/jstests/concurrency/fsm_workloads/update_check_index.js
+++ b/jstests/concurrency/fsm_workloads/update_check_index.js
@@ -20,9 +20,9 @@ var $config = (function() {
var transitions = {multiUpdate: {multiUpdate: 1.0}};
function setup(db, collName, cluster) {
- assertAlways.commandWorked(db[collName].createIndex({a: 1}));
- assertAlways.commandWorked(db[collName].createIndex({b: 1}));
- assertAlways.commandWorked(db[collName].createIndex({c: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({a: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({b: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({c: 1}));
for (var i = 0; i < 10; i++) {
assertAlways.commandWorked(db[collName].insert({a: 1, b: 1, c: 1}));
diff --git a/jstests/concurrency/fsm_workloads/update_multifield.js b/jstests/concurrency/fsm_workloads/update_multifield.js
index 311039d3877..25be0291c5a 100644
--- a/jstests/concurrency/fsm_workloads/update_multifield.js
+++ b/jstests/concurrency/fsm_workloads/update_multifield.js
@@ -52,10 +52,10 @@ var $config = (function() {
var transitions = {update: {update: 1}};
function setup(db, collName, cluster) {
- assertAlways.commandWorked(db[collName].createIndex({x: 1}));
- assertAlways.commandWorked(db[collName].createIndex({y: 1}));
- assertAlways.commandWorked(db[collName].createIndex({z: 1}));
- assertAlways.commandWorked(db[collName].createIndex({x: 1, y: 1, z: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({x: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({y: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({z: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({x: 1, y: 1, z: 1}));
// numDocs should be much less than threadCount, to make more threads use the same docs.
this.numDocs = Math.floor(this.threadCount / 3);
diff --git a/jstests/concurrency/fsm_workloads/update_rename.js b/jstests/concurrency/fsm_workloads/update_rename.js
index f76bbd5b81b..c542382fc89 100644
--- a/jstests/concurrency/fsm_workloads/update_rename.js
+++ b/jstests/concurrency/fsm_workloads/update_rename.js
@@ -43,7 +43,7 @@ var $config = (function() {
fieldNames.slice(1).forEach(function(fieldName) {
var indexSpec = {};
indexSpec[fieldName] = 1;
- assertAlways.commandWorked(db[collName].createIndex(indexSpec));
+ assertAlways.commandWorked(db[collName].ensureIndex(indexSpec));
});
// numDocs should be much less than threadCount, to make more threads use the same docs.
diff --git a/jstests/concurrency/fsm_workloads/update_replace.js b/jstests/concurrency/fsm_workloads/update_replace.js
index 1d789b8eccc..c52c12f05a9 100644
--- a/jstests/concurrency/fsm_workloads/update_replace.js
+++ b/jstests/concurrency/fsm_workloads/update_replace.js
@@ -57,12 +57,12 @@ var $config = (function() {
var transitions = {update: {update: 1}};
function setup(db, collName, cluster) {
- assertAlways.commandWorked(db[collName].createIndex({a: 1}));
- assertAlways.commandWorked(db[collName].createIndex({b: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({a: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({b: 1}));
// no index on c
- assertAlways.commandWorked(db[collName].createIndex({x: 1}));
- assertAlways.commandWorked(db[collName].createIndex({y: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({x: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({y: 1}));
// no index on z
// numDocs should be much less than threadCount, to make more threads use the same docs.
diff --git a/jstests/concurrency/fsm_workloads/update_simple.js b/jstests/concurrency/fsm_workloads/update_simple.js
index 519d807b855..2d6754ec93a 100644
--- a/jstests/concurrency/fsm_workloads/update_simple.js
+++ b/jstests/concurrency/fsm_workloads/update_simple.js
@@ -27,7 +27,7 @@ var $config = (function() {
function setup(db, collName, cluster) {
// index on 'value', the field being updated
- assertAlways.commandWorked(db[collName].createIndex({value: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({value: 1}));
// numDocs should be much less than threadCount, to make more threads use the same docs.
this.numDocs = Math.floor(this.threadCount / 5);
diff --git a/jstests/concurrency/fsm_workloads/update_upsert_multi.js b/jstests/concurrency/fsm_workloads/update_upsert_multi.js
index 34d81924bb6..bffcbc232fa 100644
--- a/jstests/concurrency/fsm_workloads/update_upsert_multi.js
+++ b/jstests/concurrency/fsm_workloads/update_upsert_multi.js
@@ -66,7 +66,7 @@ var $config = (function() {
};
function setup(db, collName, cluster) {
- assertAlways.commandWorked(db[collName].createIndex({tid: 1, i: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({tid: 1, i: 1}));
}
return {
diff --git a/jstests/concurrency/fsm_workloads/yield_geo_near.js b/jstests/concurrency/fsm_workloads/yield_geo_near.js
index f3016c5332e..e6509bb7503 100644
--- a/jstests/concurrency/fsm_workloads/yield_geo_near.js
+++ b/jstests/concurrency/fsm_workloads/yield_geo_near.js
@@ -74,7 +74,7 @@ var $config = extendWorkload($config, function($config, $super) {
}
}
assertAlways.commandWorked(bulk.execute());
- assertAlways.commandWorked(db[collName].createIndex(this.getIndexSpec()));
+ assertAlways.commandWorked(db[collName].ensureIndex(this.getIndexSpec()));
};
return $config;
diff --git a/jstests/concurrency/fsm_workloads/yield_rooted_or.js b/jstests/concurrency/fsm_workloads/yield_rooted_or.js
index 7b5cd4b3cdd..b21e918e5bc 100644
--- a/jstests/concurrency/fsm_workloads/yield_rooted_or.js
+++ b/jstests/concurrency/fsm_workloads/yield_rooted_or.js
@@ -37,8 +37,8 @@ var $config = extendWorkload($config, function($config, $super) {
$config.setup = function setup(db, collName, cluster) {
$super.setup.apply(this, arguments);
- assertAlways.commandWorked(db[collName].createIndex({c: 1}));
- assertAlways.commandWorked(db[collName].createIndex({d: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({c: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({d: 1}));
};
return $config;
diff --git a/jstests/concurrency/fsm_workloads/yield_sort_merge.js b/jstests/concurrency/fsm_workloads/yield_sort_merge.js
index 2962744a482..b66f185854d 100644
--- a/jstests/concurrency/fsm_workloads/yield_sort_merge.js
+++ b/jstests/concurrency/fsm_workloads/yield_sort_merge.js
@@ -45,7 +45,7 @@ var $config = extendWorkload($config, function($config, $super) {
$config.setup = function setup(db, collName, cluster) {
$super.setup.apply(this, arguments);
- assertAlways.commandWorked(db[collName].createIndex({a: 1, b: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({a: 1, b: 1}));
};
return $config;
diff --git a/jstests/concurrency/fsm_workloads/yield_text.js b/jstests/concurrency/fsm_workloads/yield_text.js
index 2bd4a5608ff..2b14a051b73 100644
--- a/jstests/concurrency/fsm_workloads/yield_text.js
+++ b/jstests/concurrency/fsm_workloads/yield_text.js
@@ -42,7 +42,7 @@ var $config = extendWorkload($config, function($config, $super) {
$config.setup = function setup(db, collName, cluster) {
$super.setup.apply(this, arguments);
- assertWhenOwnColl.commandWorked(db[collName].createIndex({yield_text: 'text'}));
+ assertWhenOwnColl.commandWorked(db[collName].ensureIndex({yield_text: 'text'}));
};
return $config;
diff --git a/jstests/core/all.js b/jstests/core/all.js
index a718e2615e8..9d142e6e6c4 100644
--- a/jstests/core/all.js
+++ b/jstests/core/all.js
@@ -39,5 +39,5 @@ doTest = function() {
doTest();
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
doTest();
diff --git a/jstests/core/all2.js b/jstests/core/all2.js
index 44462787d20..c6b4170a7ff 100644
--- a/jstests/core/all2.js
+++ b/jstests/core/all2.js
@@ -29,7 +29,7 @@ check(1, {"a.x": {$all: [1, 2]}}, "F");
check(1, {"a.x": {$all: [2, 3]}}, "G");
check(0, {"a.x": {$all: [1, 3]}}, "H");
-t.createIndex({"a.x": 1});
+t.ensureIndex({"a.x": 1});
state = "index";
check(1, {"a.x": {$in: [1]}}, "A");
@@ -64,7 +64,7 @@ check(1, {"a": {$all: [1, 2]}}, "F");
check(1, {"a": {$all: [2, 3]}}, "G");
check(0, {"a": {$all: [1, 3]}}, "H");
-t.createIndex({"a": 1});
+t.ensureIndex({"a": 1});
state = "more index";
check(1, {"a": {$in: [1]}}, "A");
@@ -85,5 +85,5 @@ state = "more 2";
t.drop();
t.save({name: ["harry", "jack", "tom"]});
check(0, {name: {$all: ["harry", "john"]}}, "A");
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
check(0, {name: {$all: ["harry", "john"]}}, "B");
diff --git a/jstests/core/and.js b/jstests/core/and.js
index 20fd583c31f..389aaa8d1d1 100644
--- a/jstests/core/and.js
+++ b/jstests/core/and.js
@@ -77,7 +77,7 @@ function check() {
}
check();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
check();
assert.eq(1, t.find({a: 1, $and: [{a: 2}]}).itcount());
diff --git a/jstests/core/and3.js b/jstests/core/and3.js
index 1e74db57594..6fd8e63d910 100644
--- a/jstests/core/and3.js
+++ b/jstests/core/and3.js
@@ -12,7 +12,7 @@ t.drop();
t.save({a: 1});
t.save({a: 'foo'});
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
function checkScanMatch(query, docsExamined, n) {
var e = t.find(query).hint({a: 1}).explain("executionStats");
diff --git a/jstests/core/andor.js b/jstests/core/andor.js
index 5bac12d83ca..e5e665ec398 100644
--- a/jstests/core/andor.js
+++ b/jstests/core/andor.js
@@ -47,7 +47,7 @@ test = function() {
};
test();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
test();
// Test an inequality base match.
@@ -91,5 +91,5 @@ test = function() {
t.drop();
t.save({a: 1});
test();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
test();
diff --git a/jstests/core/apitest_dbcollection.js b/jstests/core/apitest_dbcollection.js
index 00f9b6b4c4c..9bdbb8d0f91 100644
--- a/jstests/core/apitest_dbcollection.js
+++ b/jstests/core/apitest_dbcollection.js
@@ -99,7 +99,7 @@ assert.eq(0, db.getCollection("test_db").getIndexes().length, "13");
db.getCollection("test_db").save({a: 10});
assert.eq(1, db.getCollection("test_db").getIndexes().length, "14");
-db.getCollection("test_db").createIndex({a: 1});
+db.getCollection("test_db").ensureIndex({a: 1});
db.getCollection("test_db").save({a: 10});
print(tojson(db.getCollection("test_db").getIndexes()));
@@ -109,7 +109,7 @@ db.getCollection("test_db").dropIndex({a: 1});
assert.eq(1, db.getCollection("test_db").getIndexes().length, "16");
db.getCollection("test_db").save({a: 10});
-db.getCollection("test_db").createIndex({a: 1});
+db.getCollection("test_db").ensureIndex({a: 1});
db.getCollection("test_db").save({a: 10});
assert.eq(2, db.getCollection("test_db").getIndexes().length, "17");
@@ -118,8 +118,8 @@ db.getCollection("test_db").dropIndex("a_1");
assert.eq(1, db.getCollection("test_db").getIndexes().length, "18");
db.getCollection("test_db").save({a: 10, b: 11});
-db.getCollection("test_db").createIndex({a: 1});
-db.getCollection("test_db").createIndex({b: 1});
+db.getCollection("test_db").ensureIndex({a: 1});
+db.getCollection("test_db").ensureIndex({b: 1});
db.getCollection("test_db").save({a: 10, b: 12});
assert.eq(3, db.getCollection("test_db").getIndexes().length, "19");
@@ -130,8 +130,8 @@ db.getCollection("test_db").dropIndex({a: 1});
assert.eq(1, db.getCollection("test_db").getIndexes().length, "21");
db.getCollection("test_db").save({a: 10, b: 11});
-db.getCollection("test_db").createIndex({a: 1});
-db.getCollection("test_db").createIndex({b: 1});
+db.getCollection("test_db").ensureIndex({a: 1});
+db.getCollection("test_db").ensureIndex({b: 1});
db.getCollection("test_db").save({a: 10, b: 12});
assert.eq(3, db.getCollection("test_db").getIndexes().length, "22");
@@ -179,7 +179,7 @@ assert.eq(10,
// indexDetails - If true, includes 'indexDetails' field in results. Default: false.
t.drop();
t.save({a: 1});
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
collectionStats = assert.commandWorked(t.stats());
assert(!collectionStats.hasOwnProperty('indexDetails'),
'unexpected indexDetails found in db.collection.stats() result: ' + tojson(collectionStats));
diff --git a/jstests/core/array1.js b/jstests/core/array1.js
index d25b609f3d3..27addaed616 100644
--- a/jstests/core/array1.js
+++ b/jstests/core/array1.js
@@ -14,6 +14,6 @@ assert.eq(1, coll.find(x).count());
assert.commandWorked(coll.insert(x));
assert.eq(2, coll.find(x).count());
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
assert.eq(2, coll.find(x).count());
}());
diff --git a/jstests/core/array_match1.js b/jstests/core/array_match1.js
index 0c56e8d4c34..b6a0930968e 100644
--- a/jstests/core/array_match1.js
+++ b/jstests/core/array_match1.js
@@ -16,7 +16,7 @@ function test(f, m) {
}
test("a", "A");
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
test("a", "B");
t.drop();
@@ -26,5 +26,5 @@ t.insert({_id: 2, a: {b: [6, 6]}});
t.insert({_id: 3, a: {b: [5, 5]}});
test("a.b", "C");
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
test("a.b", "D");
diff --git a/jstests/core/array_match3.js b/jstests/core/array_match3.js
index 4990bdd90fd..837341afc8a 100644
--- a/jstests/core/array_match3.js
+++ b/jstests/core/array_match3.js
@@ -9,5 +9,5 @@ t.save({a: [5]});
assert.eq(2, t.count({'a.0': 5}));
// Test with index.
-t.createIndex({'a.0': 1});
+t.ensureIndex({'a.0': 1});
assert.eq(2, t.count({'a.0': 5}));
diff --git a/jstests/core/array_match4.js b/jstests/core/array_match4.js
index 54581a14b97..821e9a4f4eb 100644
--- a/jstests/core/array_match4.js
+++ b/jstests/core/array_match4.js
@@ -16,7 +16,7 @@ assert.eq(1, t.find(query_gte).itcount(), '$gte (without index)');
// with index
//
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq(1, t.find({a: [1, 2]}).count(), '$eq (with index)');
// display explain output (for index bounds)
diff --git a/jstests/core/arrayfind1.js b/jstests/core/arrayfind1.js
index 4e9330549ae..c9d75c17f65 100644
--- a/jstests/core/arrayfind1.js
+++ b/jstests/core/arrayfind1.js
@@ -26,7 +26,7 @@ t.save({a: [{x: 4}]});
assert.eq(1, t.find({a: {$elemMatch: {x: 2}}}).count(), "B1");
assert.eq(2, t.find({a: {$elemMatch: {x: {$gt: 2}}}}).count(), "B2");
-t.createIndex({"a.x": 1});
+t.ensureIndex({"a.x": 1});
assert.eq(1, t.find({a: {$elemMatch: {x: 2}}}).count(), "D1");
assert.eq(3, t.find({"a.x": 1}).count(), "D2.1");
assert.eq(3, t.find({"a.x": {$gt: 1}}).count(), "D2.2");
diff --git a/jstests/core/arrayfind2.js b/jstests/core/arrayfind2.js
index 38de844f6f4..bbceffaa126 100644
--- a/jstests/core/arrayfind2.js
+++ b/jstests/core/arrayfind2.js
@@ -25,5 +25,5 @@ t.save({a: [{x: 3}, {x: 5}]});
t.save({a: [{x: 3}, {x: 6}]});
go("no index");
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
go("index(a)");
diff --git a/jstests/core/arrayfind3.js b/jstests/core/arrayfind3.js
index 6dba0bf625f..312ae4c0349 100644
--- a/jstests/core/arrayfind3.js
+++ b/jstests/core/arrayfind3.js
@@ -8,7 +8,7 @@ t.save({a: [1, 4, 6]});
assert.eq(2, t.find({a: {$gte: 3, $lte: 5}}).itcount(), "A1");
assert.eq(1, t.find({a: {$elemMatch: {$gte: 3, $lte: 5}}}).itcount(), "A2");
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq(2, t.find({a: {$gte: 3, $lte: 5}}).itcount(), "B1");
assert.eq(1, t.find({a: {$elemMatch: {$gte: 3, $lte: 5}}}).itcount(), "B2");
diff --git a/jstests/core/arrayfind4.js b/jstests/core/arrayfind4.js
index 2d7c0e03668..4fac0b63755 100644
--- a/jstests/core/arrayfind4.js
+++ b/jstests/core/arrayfind4.js
@@ -8,7 +8,7 @@ t = db.jstests_arrayfind4;
t.drop();
t.save({a: []});
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq(1, t.find({a: []}).hint({$natural: 1}).itcount());
assert.eq(1, t.find({a: []}).hint({a: 1}).itcount());
diff --git a/jstests/core/arrayfind5.js b/jstests/core/arrayfind5.js
index 171fe49e1f8..9f8800a0c69 100644
--- a/jstests/core/arrayfind5.js
+++ b/jstests/core/arrayfind5.js
@@ -16,12 +16,12 @@ function check(nullElemMatch) {
t.save({a: [{}, {b: 1}]});
check(true);
-t.createIndex({'a.b': 1});
+t.ensureIndex({'a.b': 1});
check(true);
t.drop();
t.save({a: [5, {b: 1}]});
check(false);
-t.createIndex({'a.b': 1});
+t.ensureIndex({'a.b': 1});
check(false);
diff --git a/jstests/core/arrayfind6.js b/jstests/core/arrayfind6.js
index bd91859c9dc..f01271b6673 100644
--- a/jstests/core/arrayfind6.js
+++ b/jstests/core/arrayfind6.js
@@ -17,5 +17,5 @@ function checkElemMatchMatches() {
}
checkElemMatchMatches();
-t.createIndex({'a.b': 1});
+t.ensureIndex({'a.b': 1});
checkElemMatchMatches();
diff --git a/jstests/core/arrayfind7.js b/jstests/core/arrayfind7.js
index be2061c5c0d..699f8c9586d 100644
--- a/jstests/core/arrayfind7.js
+++ b/jstests/core/arrayfind7.js
@@ -11,7 +11,7 @@ function checkElemMatchMatches() {
// The document is matched using nested $elemMatch expressions, with and without an index.
checkElemMatchMatches();
-t.createIndex({'a.b.c': 1});
+t.ensureIndex({'a.b.c': 1});
checkElemMatchMatches();
function checkElemMatch(index, document, query) {
@@ -19,7 +19,7 @@ function checkElemMatch(index, document, query) {
t.drop();
t.save(document);
assert.eq(1, t.count(query));
- t.createIndex(index);
+ t.ensureIndex(index);
assert.eq(1, t.count(query));
t.save({a: {b: {c: [10, 11]}}}); // Make the index multikey.
assert.eq(1, t.count(query));
diff --git a/jstests/core/arrayfind9.js b/jstests/core/arrayfind9.js
index 5406ae8c1d1..98396701dce 100644
--- a/jstests/core/arrayfind9.js
+++ b/jstests/core/arrayfind9.js
@@ -25,8 +25,8 @@ assert.eq(1, t.count({a: {$elemMatch: {'0': 'x'}}}));
// Matching multiple values of a nested array.
t.drop();
t.save({a: [{b: [0, 2]}]});
-t.createIndex({a: 1});
-t.createIndex({'a.b': 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({'a.b': 1});
plans = [{$natural: 1}, {a: 1}, {'a.b': 1}];
for (i in plans) {
p = plans[i];
diff --git a/jstests/core/arrayfinda.js b/jstests/core/arrayfinda.js
index 163af3d8d29..f2939d0c1ba 100644
--- a/jstests/core/arrayfinda.js
+++ b/jstests/core/arrayfinda.js
@@ -16,6 +16,6 @@ assertExpectedMatch(t.find({a: {$elemMatch: {b: {$gte: 1}}}}));
assertExpectedMatch(t.find({a: {$elemMatch: {b: 1}}}));
// $elemMatch is not used to perform key matching. SERVER-6001
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assertExpectedMatch(t.find({a: {$elemMatch: {b: {$gte: 1}}}}).hint({a: 1}));
assertExpectedMatch(t.find({a: {$elemMatch: {b: 1}}}).hint({a: 1}));
diff --git a/jstests/core/arrayfindb.js b/jstests/core/arrayfindb.js
index 7277f51c4f4..c9456509487 100644
--- a/jstests/core/arrayfindb.js
+++ b/jstests/core/arrayfindb.js
@@ -12,7 +12,7 @@ assert.eq(0,
t.find({a: {$elemMatch: {b: {$gte: 2, $lt: 4}, c: 25}}}).itcount(),
"Case #1: wrong number of results returned -- unindexed");
-t.createIndex({"a.b": 1, "a.c": 1});
+t.ensureIndex({"a.b": 1, "a.c": 1});
assert.eq(0,
t.find({a: {$elemMatch: {b: {$gte: 2, $lt: 4}, c: 25}}}).itcount(),
"Case #1: wrong number of results returned -- indexed");
@@ -26,8 +26,8 @@ assert.eq(2,
t.find({a: {$elemMatch: {$or: [{b: 2}, {c: 2}]}}}).itcount(),
"Case #2: wrong number of results returned -- unindexed");
-t.createIndex({"a.b": 1});
-t.createIndex({"a.c": 1});
+t.ensureIndex({"a.b": 1});
+t.ensureIndex({"a.c": 1});
assert.eq(2,
t.find({a: {$elemMatch: {$or: [{b: 2}, {c: 2}]}}}).itcount(),
"Case #2: wrong number of results returned -- indexed");
diff --git a/jstests/core/bad_index_plugin.js b/jstests/core/bad_index_plugin.js
index c9cd549cc03..7ecfe76c198 100644
--- a/jstests/core/bad_index_plugin.js
+++ b/jstests/core/bad_index_plugin.js
@@ -1,10 +1,10 @@
// SERVER-5826 ensure you can't build an index with a non-existent plugin
t = db.bad_index_plugin;
-assert.commandWorked(t.createIndex({good: 1}));
+assert.commandWorked(t.ensureIndex({good: 1}));
assert.eq(t.getIndexes().length, 2); // good + _id
-var err = t.createIndex({bad: 'bad'});
+var err = t.ensureIndex({bad: 'bad'});
assert.commandFailed(err);
assert(err.code >= 0);
diff --git a/jstests/core/basic7.js b/jstests/core/basic7.js
index dc6f18cc95b..bfe82ccda17 100644
--- a/jstests/core/basic7.js
+++ b/jstests/core/basic7.js
@@ -3,7 +3,7 @@ t = db.basic7;
t.drop();
t.save({a: 1});
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq(t.find().toArray()[0].a, 1);
assert.eq(t.find().arrayAccess(0).a, 1);
diff --git a/jstests/core/batch_size.js b/jstests/core/batch_size.js
index c0afc382975..11ea9cd2380 100644
--- a/jstests/core/batch_size.js
+++ b/jstests/core/batch_size.js
@@ -46,7 +46,7 @@ assert.eq(1, t.find().batchSize(-1).itcount());
assert.eq(2, t.find().batchSize(-2).itcount());
// Run the tests with the index twice in order to double check plan caching.
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
for (var i = 0; i < 2; i++) {
runIndexedTests();
}
@@ -54,8 +54,8 @@ for (var i = 0; i < 2; i++) {
// The next tests make sure that we obey limit and batchSize properly when the sort could be
// either indexed or unindexed.
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
for (var i = 0; i < 100; i++) {
t.save({_id: i, a: i, b: 1});
@@ -118,8 +118,8 @@ for (var i = 0; i < nDocs; i++) {
}
// Two indices needed in order to trigger plan ranking. Neither index provides the sort order.
-t.createIndex({x: 1});
-t.createIndex({y: 1});
+t.ensureIndex({x: 1});
+t.ensureIndex({y: 1});
// We should only buffer 3 docs in memory.
var cursor = t.find({x: 1, y: 1}).sort({z: -1}).limit(3);
diff --git a/jstests/core/batch_write_command_insert.js b/jstests/core/batch_write_command_insert.js
index 664ff73958a..cf1b0013ef7 100644
--- a/jstests/core/batch_write_command_insert.js
+++ b/jstests/core/batch_write_command_insert.js
@@ -179,7 +179,7 @@ assert(resultNOK(result), tojson(result));
//
// Should fail single insert due to duplicate key
coll.drop();
-coll.createIndex({a: 1}, {unique: true});
+coll.ensureIndex({a: 1}, {unique: true});
coll.insert({a: 1});
request = {
insert: coll.getName(),
@@ -194,7 +194,7 @@ assert.eq(coll.count(), 1);
//
// Fail with duplicate key error on multiple document inserts, ordered false
coll.drop();
-coll.createIndex({a: 1}, {unique: true});
+coll.ensureIndex({a: 1}, {unique: true});
request = {
insert: coll.getName(),
documents: [{a: 1}, {a: 1}, {a: 1}],
@@ -220,7 +220,7 @@ assert.eq(coll.count(), 1);
//
// Fail with duplicate key error on multiple document inserts, ordered true
coll.drop();
-coll.createIndex({a: 1}, {unique: true});
+coll.ensureIndex({a: 1}, {unique: true});
request = {
insert: coll.getName(),
documents: [{a: 1}, {a: 1}, {a: 1}],
@@ -241,7 +241,7 @@ assert.eq(coll.count(), 1);
//
// Ensure _id is the first field in all documents
coll.drop();
-coll.createIndex({a: 1}, {unique: true});
+coll.ensureIndex({a: 1}, {unique: true});
request = {
insert: coll.getName(),
documents: [{a: 1}, {a: 2, _id: 2}]
diff --git a/jstests/core/batch_write_command_update.js b/jstests/core/batch_write_command_update.js
index f6372a651af..edb90be8523 100644
--- a/jstests/core/batch_write_command_update.js
+++ b/jstests/core/batch_write_command_update.js
@@ -235,7 +235,7 @@ assert.eq(1, coll.count());
//
// Upsert fail due to duplicate key index, w:1, ordered:true
coll.drop();
-coll.createIndex({a: 1}, {unique: true});
+coll.ensureIndex({a: 1}, {unique: true});
request = {
update: coll.getName(),
updates: [
@@ -266,7 +266,7 @@ assert.eq(1, coll.count({_id: result.upserted[1]._id}));
//
// Upsert fail due to duplicate key index, w:1, ordered:false
coll.drop();
-coll.createIndex({a: 1}, {unique: true});
+coll.ensureIndex({a: 1}, {unique: true});
request = {
update: coll.getName(),
updates: [
diff --git a/jstests/core/batch_write_command_w0.js b/jstests/core/batch_write_command_w0.js
index ca2522bbe01..01b9cb5f165 100644
--- a/jstests/core/batch_write_command_w0.js
+++ b/jstests/core/batch_write_command_w0.js
@@ -76,7 +76,7 @@ countEventually(coll, 2);
//
// Upsert fail due to duplicate key index, w:0, ordered:true
coll.drop();
-coll.createIndex({a: 1}, {unique: true});
+coll.ensureIndex({a: 1}, {unique: true});
request = {
update: coll.getName(),
updates: [
diff --git a/jstests/core/bulk_api_ordered.js b/jstests/core/bulk_api_ordered.js
index d3a484c2b12..2957195065d 100644
--- a/jstests/core/bulk_api_ordered.js
+++ b/jstests/core/bulk_api_ordered.js
@@ -80,7 +80,7 @@ var executeTests = function() {
// Create unique index
coll.remove({});
- coll.createIndex({a: 1}, {unique: true});
+ coll.ensureIndex({a: 1}, {unique: true});
/**
* Single error ordered bulk operation
@@ -118,7 +118,7 @@ var executeTests = function() {
// Create unique index
coll.dropIndexes();
coll.remove({});
- coll.createIndex({a: 1}, {unique: true});
+ coll.ensureIndex({a: 1}, {unique: true});
/**
* Multiple error ordered bulk operation
@@ -152,7 +152,7 @@ var executeTests = function() {
// Create unique index
coll.dropIndexes();
coll.remove({});
- coll.createIndex({a: 1}, {unique: true});
+ coll.ensureIndex({a: 1}, {unique: true});
};
var buildVersion = parseInt(db.runCommand({buildInfo: 1}).versionArray.slice(0, 3).join(""), 10);
diff --git a/jstests/core/bulk_api_unordered.js b/jstests/core/bulk_api_unordered.js
index 04e002306e5..6db2a607a25 100644
--- a/jstests/core/bulk_api_unordered.js
+++ b/jstests/core/bulk_api_unordered.js
@@ -85,7 +85,7 @@ var executeTests = function() {
// Create unique index
coll.remove({});
- coll.createIndex({a: 1}, {unique: true});
+ coll.ensureIndex({a: 1}, {unique: true});
/**
* Single error unordered bulk operation
@@ -118,7 +118,7 @@ var executeTests = function() {
// Create unique index
coll.dropIndexes();
coll.remove({});
- coll.createIndex({a: 1}, {unique: true});
+ coll.ensureIndex({a: 1}, {unique: true});
/**
* Multiple error unordered bulk operation
@@ -168,7 +168,7 @@ var executeTests = function() {
// Create unique index
coll.dropIndexes();
coll.remove({});
- coll.createIndex({a: 1}, {unique: true});
+ coll.ensureIndex({a: 1}, {unique: true});
};
var buildVersion = parseInt(db.runCommand({buildInfo: 1}).versionArray.slice(0, 3).join(""), 10);
diff --git a/jstests/core/capped5.js b/jstests/core/capped5.js
index 163aa684fbe..0efb957ae6c 100644
--- a/jstests/core/capped5.js
+++ b/jstests/core/capped5.js
@@ -9,8 +9,8 @@ t.insert({_id: 5, x: 11, z: 52});
assert.eq(1, t.getIndexKeys().length, "A0"); // now we assume _id index even on capped coll
assert.eq(52, t.findOne({x: 11}).z, "A1");
-t.createIndex({_id: 1});
-t.createIndex({x: 1});
+t.ensureIndex({_id: 1});
+t.ensureIndex({x: 1});
assert.eq(52, t.findOne({x: 11}).z, "B1");
assert.eq(52, t.findOne({_id: 5}).z, "B2");
@@ -26,14 +26,14 @@ t.drop();
db.createCollection(tn, {capped: true, size: 1024 * 1024 * 1});
t.insert({_id: 5, x: 11});
t.insert({_id: 6, x: 12});
-t.createIndex({x: 1}, {unique: true});
+t.ensureIndex({x: 1}, {unique: true});
assert.eq(2, t.getIndexes().length); // now we assume _id index
assert.eq(2, t.find().hint({x: 1}).toArray().length);
// SERVER-525 (closed) unique indexes in capped collection
t.drop();
db.createCollection(tn, {capped: true, size: 1024 * 1024 * 1});
-t.createIndex({_id: 1}); // note we assume will be automatically unique because it is _id
+t.ensureIndex({_id: 1}); // note we assume will be automatically unique because it is _id
t.insert({_id: 5, x: 11});
t.insert({_id: 5, x: 12});
assert.eq(1, t.find().toArray().length);
diff --git a/jstests/core/capped_empty.js b/jstests/core/capped_empty.js
index 93657b4a67f..99e08f217ed 100644
--- a/jstests/core/capped_empty.js
+++ b/jstests/core/capped_empty.js
@@ -14,7 +14,7 @@ db.createCollection(t.getName(), {capped: true, size: 100});
t.insert({x: 1});
t.insert({x: 2});
t.insert({x: 3});
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq(3, t.count());
diff --git a/jstests/core/cappeda.js b/jstests/core/cappeda.js
index 1061ba0a1d6..f506d5416b1 100644
--- a/jstests/core/cappeda.js
+++ b/jstests/core/cappeda.js
@@ -22,7 +22,7 @@ function u() {
// assert.throws( q , [] , "A1" );
// assert.throws( u , [] , "B1" );
-t.createIndex({_id: 1});
+t.ensureIndex({_id: 1});
assert.eq(1, q().x);
q();
diff --git a/jstests/core/check_shard_index.js b/jstests/core/check_shard_index.js
index e64beee77f8..f187a6210d0 100644
--- a/jstests/core/check_shard_index.js
+++ b/jstests/core/check_shard_index.js
@@ -16,7 +16,7 @@ f.drop();
//
f.drop();
-f.createIndex({x: 1, y: 1});
+f.ensureIndex({x: 1, y: 1});
assert.eq(0, f.count(), "1. initial count should be zero");
res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}});
@@ -32,7 +32,7 @@ assert.eq(true, res.ok, "1b");
//
f.drop();
-f.createIndex({x: 1, y: 1});
+f.ensureIndex({x: 1, y: 1});
assert.eq(0, f.count(), "2. initial count should be zero");
f.save({x: 1, y: 1});
@@ -56,7 +56,7 @@ assert(res.idskip, "2d " + tojson(res));
//
f.drop();
-f.createIndex({x: 1, y: 1});
+f.ensureIndex({x: 1, y: 1});
assert.eq(0, f.count(), "3. initial count should be zero");
f.save({x: 1, y: 1});
@@ -68,7 +68,7 @@ assert.eq(false, res.ok, "3a " + tojson(res));
f.remove({y: 2});
f.dropIndex({x: 1, y: 1});
-f.createIndex({x: 1, y: 1});
+f.ensureIndex({x: 1, y: 1});
assert.eq(1, f.count(), "3. count after removing array value should be 1");
res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}});
@@ -85,7 +85,7 @@ assert.eq(false, res.ok, "3c " + tojson(res));
//
f.drop();
-f.createIndex({x: 1, y: 1, z: 1});
+f.ensureIndex({x: 1, y: 1, z: 1});
assert.eq(0, f.count(), "4. initial count should be zero");
f.save({x: 1, y: 1, z: 1});
@@ -110,7 +110,7 @@ assert.eq(false, res.ok, "4e " + tojson(res));
f.remove({y: 2});
f.dropIndex({x: 1, y: 1, z: 1});
-f.createIndex({x: 1, y: 1, z: 1});
+f.ensureIndex({x: 1, y: 1, z: 1});
assert.eq(1, f.count(), "4. count after removing array value should be 1");
res = db.runCommand(
@@ -131,7 +131,7 @@ assert.eq(false, res.ok, "4i " + tojson(res));
f.remove({x: 3});
// Necessary so that the index is no longer marked as multikey
f.dropIndex({x: 1, y: 1, z: 1});
-f.createIndex({x: 1, y: 1, z: 1});
+f.ensureIndex({x: 1, y: 1, z: 1});
assert.eq(1, f.count(), "4. count after removing array value should be 1 again");
res = db.runCommand(
diff --git a/jstests/core/collation.js b/jstests/core/collation.js
index 44e8092f75e..5cfedcc8e1f 100644
--- a/jstests/core/collation.js
+++ b/jstests/core/collation.js
@@ -99,7 +99,7 @@ assert.eq(collectionInfos[0].options.collation, {
});
// Ensure that an index with no collation inherits the collection-default collation.
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
assertIndexHasCollation({a: 1}, {
locale: "fr_CA",
caseLevel: false,
@@ -115,7 +115,7 @@ assertIndexHasCollation({a: 1}, {
// Ensure that an index which specifies an overriding collation does not use the collection
// default.
-assert.commandWorked(coll.createIndex({b: 1}, {collation: {locale: "en_US"}}));
+assert.commandWorked(coll.ensureIndex({b: 1}, {collation: {locale: "en_US"}}));
assertIndexHasCollation({b: 1}, {
locale: "en_US",
caseLevel: false,
@@ -131,11 +131,11 @@ assertIndexHasCollation({b: 1}, {
// Ensure that an index which specifies the "simple" collation as an overriding collation still
// does not use the collection default.
-assert.commandWorked(coll.createIndex({d: 1}, {collation: {locale: "simple"}}));
+assert.commandWorked(coll.ensureIndex({d: 1}, {collation: {locale: "simple"}}));
assertIndexHasCollation({d: 1}, {locale: "simple"});
// Ensure that a v=1 index doesn't inherit the collection-default collation.
-assert.commandWorked(coll.createIndex({c: 1}, {v: 1}));
+assert.commandWorked(coll.ensureIndex({c: 1}, {v: 1}));
assertIndexHasCollation({c: 1}, {locale: "simple"});
// Test that all indexes retain their current collation when the collection is re-indexed. (Only
@@ -177,20 +177,20 @@ coll.drop();
//
// Attempting to build an index with an invalid collation should fail.
-assert.commandFailed(coll.createIndex({a: 1}, {collation: "not an object"}));
-assert.commandFailed(coll.createIndex({a: 1}, {collation: {}}));
-assert.commandFailed(coll.createIndex({a: 1}, {collation: {blah: 1}}));
-assert.commandFailed(coll.createIndex({a: 1}, {collation: {locale: "en", blah: 1}}));
-assert.commandFailed(coll.createIndex({a: 1}, {collation: {locale: "xx"}}));
-assert.commandFailed(coll.createIndex({a: 1}, {collation: {locale: "en", strength: 99}}));
+assert.commandFailed(coll.ensureIndex({a: 1}, {collation: "not an object"}));
+assert.commandFailed(coll.ensureIndex({a: 1}, {collation: {}}));
+assert.commandFailed(coll.ensureIndex({a: 1}, {collation: {blah: 1}}));
+assert.commandFailed(coll.ensureIndex({a: 1}, {collation: {locale: "en", blah: 1}}));
+assert.commandFailed(coll.ensureIndex({a: 1}, {collation: {locale: "xx"}}));
+assert.commandFailed(coll.ensureIndex({a: 1}, {collation: {locale: "en", strength: 99}}));
// Attempting to create an index whose collation version does not match the collator version
// produced by ICU should result in failure with a special error code.
assert.commandFailedWithCode(
- coll.createIndex({a: 1}, {collation: {locale: "en", version: "unknownVersion"}}),
+ coll.ensureIndex({a: 1}, {collation: {locale: "en", version: "unknownVersion"}}),
ErrorCodes.IncompatibleCollationVersion);
-assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "en_US"}}));
assertIndexHasCollation({a: 1}, {
locale: "en_US",
caseLevel: false,
@@ -335,7 +335,7 @@ assert.eq(0, coll.aggregate([{$match: {str: "FOO"}}], {collation: {locale: "simp
// default collation.
coll.drop();
assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
-assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "en_US"}}));
var explain = coll.explain("queryPlanner").aggregate([{$match: {a: "foo"}}]);
assert(isIxscan(db, explain.queryPlanner.winningPlan));
@@ -343,7 +343,7 @@ assert(isIxscan(db, explain.queryPlanner.winningPlan));
// collation is incompatible with index collation.
coll.drop();
assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
-assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "simple"}}));
var explain = coll.explain("queryPlanner").aggregate([{$match: {a: "foo"}}]);
assert(isCollscan(db, explain.queryPlanner.winningPlan));
@@ -505,7 +505,7 @@ assert.eq(1, coll.distinct("_id", {str: "foo"}, {collation: {locale: "simple"}})
// default collation.
coll.drop();
assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
-assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "en_US"}}));
var explain = coll.explain("queryPlanner").distinct("a");
assert(planHasStage(db, explain.queryPlanner.winningPlan, "DISTINCT_SCAN"));
assert(planHasStage(db, explain.queryPlanner.winningPlan, "FETCH"));
@@ -534,7 +534,7 @@ assert(!planHasStage(db, explain.queryPlanner.winningPlan, "FETCH"));
// incompatible with index collation.
coll.drop();
assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
-assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "simple"}}));
var explain = coll.explain("queryPlanner").distinct("a");
assert(isCollscan(db, explain.queryPlanner.winningPlan));
@@ -608,7 +608,7 @@ if (db.getMongo().useReadCommands()) {
coll.find({str: {$ne: "FOO"}}).collation({locale: "en_US", strength: 2}).itcount());
// Find should return correct results when collation specified and compatible index exists.
- assert.commandWorked(coll.createIndex({str: 1}, {collation: {locale: "en_US", strength: 2}}));
+ assert.commandWorked(coll.ensureIndex({str: 1}, {collation: {locale: "en_US", strength: 2}}));
assert.eq(0, coll.find({str: "FOO"}).hint({str: 1}).itcount());
assert.eq(0, coll.find({str: "FOO"}).collation({locale: "en_US"}).hint({str: 1}).itcount());
assert.eq(
@@ -623,7 +623,7 @@ if (db.getMongo().useReadCommands()) {
// Find should return correct results when collation specified and compatible partial index
// exists.
- assert.commandWorked(coll.createIndex({str: 1}, {
+ assert.commandWorked(coll.ensureIndex({str: 1}, {
partialFilterExpression: {str: {$lte: "FOO"}},
collation: {locale: "en_US", strength: 2}
}));
@@ -644,7 +644,7 @@ if (db.getMongo().useReadCommands()) {
// Ensure results from an index that doesn't match the query collation are sorted to match
// the requested collation.
- assert.commandWorked(coll.createIndex({a: 1}));
+ assert.commandWorked(coll.ensureIndex({a: 1}));
var res =
coll.find({a: {'$exists': true}}, {_id: 0}).collation({locale: "en_US", strength: 3}).sort({
a: 1
@@ -746,7 +746,7 @@ if (db.getMongo().useReadCommands()) {
// collation.
coll.drop();
assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
-assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "en_US"}}));
var explain = coll.find({a: "foo"}).explain("queryPlanner");
assert(isIxscan(db, explain.queryPlanner.winningPlan));
@@ -754,7 +754,7 @@ assert(isIxscan(db, explain.queryPlanner.winningPlan));
// collation is "simple".
coll.drop();
assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "simple"}}));
-assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "simple"}}));
var explain = coll.find({a: "foo"}).explain("queryPlanner");
assert(isIxscan(db, explain.queryPlanner.winningPlan));
@@ -762,7 +762,7 @@ assert(isIxscan(db, explain.queryPlanner.winningPlan));
// collection has a non-"simple" default collation.
coll.drop();
assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
-assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "simple"}}));
var explain = coll.find({a: "foo"}).explain("queryPlanner");
assert(isCollscan(db, explain.queryPlanner.winningPlan));
@@ -770,7 +770,7 @@ assert(isCollscan(db, explain.queryPlanner.winningPlan));
// non-"simple" default collation.
coll.drop();
assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
-assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "simple"}}));
var explain = coll.find({a: "foo"}).collation({locale: "simple"}).explain("queryPlanner");
assert(isIxscan(db, explain.queryPlanner.winningPlan));
@@ -1314,14 +1314,14 @@ const geoNearStage = {
// $geoNear should return correct results when collation specified and string predicate not
// indexed.
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}));
assert.eq(0, coll.aggregate([geoNearStage]).itcount());
assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", strength: 2}}).itcount());
// $geoNear should return correct results when no collation specified and string predicate
// indexed.
assert.commandWorked(coll.dropIndexes());
-assert.commandWorked(coll.createIndex({geo: "2dsphere", str: 1}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere", str: 1}));
assert.eq(0, coll.aggregate([geoNearStage]).itcount());
assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", strength: 2}}).itcount());
@@ -1329,7 +1329,7 @@ assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", streng
// incompatible with string predicate.
assert.commandWorked(coll.dropIndexes());
assert.commandWorked(
- coll.createIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 3}}));
+ coll.ensureIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 3}}));
assert.eq(0, coll.aggregate([geoNearStage]).itcount());
assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", strength: 2}}).itcount());
@@ -1337,7 +1337,7 @@ assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", streng
// compatible with string predicate.
assert.commandWorked(coll.dropIndexes());
assert.commandWorked(
- coll.createIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 2}}));
+ coll.ensureIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 2}}));
assert.eq(0, coll.aggregate([geoNearStage]).itcount());
assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", strength: 2}}).itcount());
@@ -1346,7 +1346,7 @@ assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", streng
coll.drop();
assert.commandWorked(
db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}));
assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"}));
assert.eq(1, coll.aggregate([geoNearStage]).itcount());
@@ -1355,7 +1355,7 @@ assert.eq(1, coll.aggregate([geoNearStage]).itcount());
coll.drop();
assert.commandWorked(
db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}));
assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"}));
assert.eq(0, coll.aggregate([geoNearStage], {collation: {locale: "simple"}}).itcount());
@@ -1378,7 +1378,7 @@ if (db.getMongo().useReadCommands()) {
// predicate not indexed.
coll.drop();
assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"}));
- assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
+ assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}));
assert.eq(
0,
coll.find(
@@ -1394,7 +1394,7 @@ if (db.getMongo().useReadCommands()) {
// Find with $nearSphere should return correct results when no collation specified and
// string predicate indexed.
assert.commandWorked(coll.dropIndexes());
- assert.commandWorked(coll.createIndex({geo: "2dsphere", str: 1}));
+ assert.commandWorked(coll.ensureIndex({geo: "2dsphere", str: 1}));
assert.eq(
0,
coll.find(
@@ -1411,7 +1411,7 @@ if (db.getMongo().useReadCommands()) {
// collation on index is incompatible with string predicate.
assert.commandWorked(coll.dropIndexes());
assert.commandWorked(
- coll.createIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 3}}));
+ coll.ensureIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 3}}));
assert.eq(
0,
coll.find(
@@ -1428,7 +1428,7 @@ if (db.getMongo().useReadCommands()) {
// collation on index is compatible with string predicate.
assert.commandWorked(coll.dropIndexes());
assert.commandWorked(
- coll.createIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 2}}));
+ coll.ensureIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 2}}));
assert.eq(
0,
coll.find(
@@ -1886,7 +1886,7 @@ if (db.getMongo().useReadCommands()) {
// Ensure results from index with min/max query are sorted to match requested collation.
coll.drop();
- assert.commandWorked(coll.createIndex({a: 1, b: 1}));
+ assert.commandWorked(coll.ensureIndex({a: 1, b: 1}));
assert.commandWorked(
coll.insert([{a: 1, b: 1}, {a: 1, b: 2}, {a: 1, b: "A"}, {a: 1, b: "a"}, {a: 2, b: 2}]));
var expected = [{a: 1, b: 1}, {a: 1, b: 2}, {a: 1, b: "a"}, {a: 1, b: "A"}, {a: 2, b: 2}];
diff --git a/jstests/core/collmod.js b/jstests/core/collmod.js
index 2f71b39c485..c70a806c2d7 100644
--- a/jstests/core/collmod.js
+++ b/jstests/core/collmod.js
@@ -53,7 +53,7 @@ function findCollectionInfo() {
assert.commandFailed(t.runCommand('collmod', {NotARealOption: 1}));
// add a TTL index
-t.createIndex({a: 1}, {"name": "index1", "expireAfterSeconds": 50});
+t.ensureIndex({a: 1}, {"name": "index1", "expireAfterSeconds": 50});
assert(findTTL({a: 1}, 50), "TTL index not added");
// try to modify it with a bad key pattern
@@ -98,7 +98,7 @@ assert.commandFailed(db.runCommand({
// try to modify a faulty TTL index with a non-numeric expireAfterSeconds field
t.dropIndex({a: 1});
-t.createIndex({a: 1}, {"expireAfterSeconds": "50"});
+t.ensureIndex({a: 1}, {"expireAfterSeconds": "50"});
var res =
db.runCommand({"collMod": coll, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": 100}});
debug(res);
@@ -106,7 +106,7 @@ assert.eq(0, res.ok, "shouldn't be able to modify faulty index spec");
// try with new index, this time set expireAfterSeconds
t.dropIndex({a: 1});
-t.createIndex({a: 1}, {"expireAfterSeconds": 50});
+t.ensureIndex({a: 1}, {"expireAfterSeconds": 50});
var res =
db.runCommand({"collMod": coll, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": 100}});
debug(res);
diff --git a/jstests/core/compact_keeps_indexes.js b/jstests/core/compact_keeps_indexes.js
index f4f59165272..4371513b3d9 100644
--- a/jstests/core/compact_keeps_indexes.js
+++ b/jstests/core/compact_keeps_indexes.js
@@ -15,7 +15,7 @@ var coll = db.compact_keeps_indexes;
coll.drop();
coll.insert({_id: 1, x: 1});
-coll.createIndex({x: 1});
+coll.ensureIndex({x: 1});
assert.eq(coll.getIndexes().length, 2);
diff --git a/jstests/core/count.js b/jstests/core/count.js
index c34f8721cef..523b0743c3f 100644
--- a/jstests/core/count.js
+++ b/jstests/core/count.js
@@ -17,13 +17,13 @@ assert.eq(2, coll.count());
coll.drop();
assert.commandWorked(coll.insert({a: true, b: false}));
-assert.commandWorked(coll.createIndex({b: 1, a: 1}));
+assert.commandWorked(coll.ensureIndex({b: 1, a: 1}));
assert.eq(1, coll.find({a: true, b: false}).count());
assert.eq(1, coll.find({b: false, a: true}).count());
coll.drop();
assert.commandWorked(coll.insert({a: true, b: false}));
-assert.commandWorked(coll.createIndex({b: 1, a: 1, c: 1}));
+assert.commandWorked(coll.ensureIndex({b: 1, a: 1, c: 1}));
assert.eq(1, coll.find({a: true, b: false}).count());
assert.eq(1, coll.find({b: false, a: true}).count());
diff --git a/jstests/core/count4.js b/jstests/core/count4.js
index 2bb35190bd8..ac0b3d3491f 100644
--- a/jstests/core/count4.js
+++ b/jstests/core/count4.js
@@ -13,7 +13,7 @@ q = {
assert.eq(50, t.find(q).count(), "A");
assert.eq(50, t.find(q).itcount(), "B");
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq(50, t.find(q).count(), "C");
assert.eq(50, t.find(q).itcount(), "D");
diff --git a/jstests/core/count5.js b/jstests/core/count5.js
index ceedf62b336..b89eb88d494 100644
--- a/jstests/core/count5.js
+++ b/jstests/core/count5.js
@@ -14,7 +14,7 @@ q = {
assert.eq(50, t.find(q).count(), "A");
assert.eq(50, t.find(q).itcount(), "B");
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq(50, t.find(q).count(), "C");
assert.eq(50, t.find(q).itcount(), "D");
diff --git a/jstests/core/count6.js b/jstests/core/count6.js
index 78735c89c26..46fb428ef97 100644
--- a/jstests/core/count6.js
+++ b/jstests/core/count6.js
@@ -6,7 +6,7 @@ t = db.jstests_count6;
function checkCountForObject(obj) {
t.drop();
- t.createIndex({b: 1, a: 1});
+ t.ensureIndex({b: 1, a: 1});
function checkCounts(query, expected) {
assert.eq(expected, t.count(query), "A1");
diff --git a/jstests/core/count7.js b/jstests/core/count7.js
index 443134474a8..95417e241de 100644
--- a/jstests/core/count7.js
+++ b/jstests/core/count7.js
@@ -5,7 +5,7 @@
t = db.jstests_count7;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: 'algebra'});
t.save({a: 'apple'});
t.save({a: 'azores'});
diff --git a/jstests/core/count9.js b/jstests/core/count9.js
index 062f099e513..517322a9310 100644
--- a/jstests/core/count9.js
+++ b/jstests/core/count9.js
@@ -3,7 +3,7 @@
t = db.jstests_count9;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: ['a', 'b', 'a']});
assert.eq(1, t.count({a: 'a'}));
@@ -12,7 +12,7 @@ t.save({a: ['a', 'b', 'a']});
assert.eq(2, t.count({a: 'a'}));
t.drop();
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
t.save({a: ['a', 'b', 'a'], b: 'r'});
assert.eq(1, t.count({a: 'a', b: 'r'}));
@@ -23,6 +23,6 @@ assert.eq(2, t.count({a: 'a', b: 'r'}));
assert.eq(2, t.count({a: 'a'}));
t.drop();
-t.createIndex({'a.b': 1, 'a.c': 1});
+t.ensureIndex({'a.b': 1, 'a.c': 1});
t.save({a: [{b: 'b', c: 'c'}, {b: 'b', c: 'c'}]});
assert.eq(1, t.count({'a.b': 'b', 'a.c': 'c'}));
diff --git a/jstests/core/count_hint.js b/jstests/core/count_hint.js
index 5ba9514de87..21c7a37b87d 100644
--- a/jstests/core/count_hint.js
+++ b/jstests/core/count_hint.js
@@ -18,7 +18,7 @@ assert.commandWorked(coll.insert({i: 2}));
assert.eq(2, coll.find().count());
-assert.commandWorked(coll.createIndex({i: 1}));
+assert.commandWorked(coll.ensureIndex({i: 1}));
assert.eq(2, coll.find().hint("i_1").count());
assert.eq(2, coll.find().hint({i: 1}).count());
@@ -30,7 +30,7 @@ assert.eq(2, coll.find().hint("_id_").count());
assert.eq(2, coll.find().hint({_id: 1}).count());
// Create a sparse index which should have no entries.
-assert.commandWorked(coll.createIndex({x: 1}, {sparse: true}));
+assert.commandWorked(coll.ensureIndex({x: 1}, {sparse: true}));
// A hint should be respected, even if it results in the wrong answer.
assert.eq(0, coll.find().hint("x_1").count());
diff --git a/jstests/core/countb.js b/jstests/core/countb.js
index 869825b25a1..bd6f9507fd2 100644
--- a/jstests/core/countb.js
+++ b/jstests/core/countb.js
@@ -7,7 +7,7 @@
t = db.jstests_countb;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: ['a', 'b']});
assert.eq(0, t.find({a: {$in: ['a'], $gt: 'b'}}).count());
assert.eq(0, t.find({$and: [{a: 'a'}, {a: {$gt: 'b'}}]}).count());
diff --git a/jstests/core/countc.js b/jstests/core/countc.js
index 5f0d31b769c..876129c573f 100644
--- a/jstests/core/countc.js
+++ b/jstests/core/countc.js
@@ -14,7 +14,7 @@ t.drop();
// Match a subset of inserted values within a $in operator.
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
// Save 'a' values 0, 0.5, 1.5, 2.5 ... 97.5, 98.5, 99.
t.save({a: 0});
t.save({a: 99});
@@ -31,7 +31,7 @@ assert.eq(2, t.count({a: {$in: vals}}));
// Match 'a' values within upper and lower limits.
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: [1, 2]}); // Will match because 'a' is in range.
t.save({a: 9}); // Will not match because 'a' is not in range.
// Only one document matches.
@@ -39,14 +39,14 @@ assert.eq(1, t.count({a: {$gt: 0, $lt: 5}}));
// Match two nested fields within an array.
t.drop();
-t.createIndex({'a.b': 1, 'a.c': 1});
+t.ensureIndex({'a.b': 1, 'a.c': 1});
t.save({a: [{b: 2, c: 3}, {}]});
// The document does not match because its c value is 3.
assert.eq(0, t.count({'a.b': 2, 'a.c': 2}));
// $gt:string only matches strings.
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: 'a'}); // Will match.
t.save({a: {}}); // Will not match because {} is not a string.
// Only one document matches.
@@ -54,7 +54,7 @@ assert.eq(1, t.count({a: {$gte: ''}}));
// $lte:date only matches dates.
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: new Date(1)}); // Will match.
t.save({a: true}); // Will not match because 'true' is not a date.
// Only one document matches.
@@ -62,14 +62,14 @@ assert.eq(1, t.count({a: {$lte: new Date(1)}}));
// Querying for 'undefined' triggers an error.
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.throws(function() {
t.count({a: undefined});
});
// Count using a descending order index.
t.drop();
-t.createIndex({a: -1});
+t.ensureIndex({a: -1});
t.save({a: 1});
t.save({a: 2});
t.save({a: 3});
@@ -80,7 +80,7 @@ assert.eq(2, t.count({a: {$lt: 3}}));
// Count using a compound index.
t.drop();
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
t.save({a: 1, b: 2});
t.save({a: 2, b: 1});
t.save({a: 2, b: 3});
@@ -95,7 +95,7 @@ assert.eq(1, t.count({a: 1, b: {$lt: 3}}));
// Count using a compound descending order index.
t.drop();
-t.createIndex({a: 1, b: -1});
+t.ensureIndex({a: 1, b: -1});
t.save({a: 1, b: 2});
t.save({a: 2, b: 1});
t.save({a: 2, b: 3});
@@ -108,13 +108,13 @@ assert.eq(1, t.count({a: 1, b: {$lt: 3}}));
// Count with a multikey value.
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: [1, 2]});
assert.eq(1, t.count({a: {$gt: 0, $lte: 2}}));
// Count with a match constraint on an unindexed field.
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: 1, b: 1});
t.save({a: 1, b: 2});
assert.eq(1, t.count({a: 1, $where: 'this.b == 1'}));
diff --git a/jstests/core/coveredIndex2.js b/jstests/core/coveredIndex2.js
index 41092e7d525..9ec3ce529ae 100644
--- a/jstests/core/coveredIndex2.js
+++ b/jstests/core/coveredIndex2.js
@@ -19,7 +19,7 @@ assert.eq(t.findOne({a: 1}).a, 1, "Cannot find right record");
assert.eq(t.count(), 2, "Not right length");
// use simple index
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
var plan = t.find({a: 1}).explain();
assert(!isIndexOnly(db, plan.queryPlanner.winningPlan),
"Find using covered index but all fields are returned");
diff --git a/jstests/core/coveredIndex3.js b/jstests/core/coveredIndex3.js
index 8b15b40e862..a054840b6df 100644
--- a/jstests/core/coveredIndex3.js
+++ b/jstests/core/coveredIndex3.js
@@ -30,7 +30,7 @@ if (0) { // SERVER-4975
for (i = 0; i < 30; ++i) {
t.drop();
- t.createIndex({a: 1});
+ t.ensureIndex({a: 1});
for (j = 0; j < 1000; ++j) {
t.save({a: j});
diff --git a/jstests/core/coveredIndex4.js b/jstests/core/coveredIndex4.js
index e62162d1685..125cf22da3a 100644
--- a/jstests/core/coveredIndex4.js
+++ b/jstests/core/coveredIndex4.js
@@ -9,8 +9,8 @@
t = db.jstests_coveredIndex4;
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
orClause = [];
for (i = 0; i < 200; ++i) {
diff --git a/jstests/core/covered_index_compound_1.js b/jstests/core/covered_index_compound_1.js
index a43a4f70ec5..2f2d45adabd 100644
--- a/jstests/core/covered_index_compound_1.js
+++ b/jstests/core/covered_index_compound_1.js
@@ -16,7 +16,7 @@ coll.drop();
for (i = 0; i < 100; i++) {
coll.insert({a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10)});
}
-coll.createIndex({a: 1, b: -1, c: 1});
+coll.ensureIndex({a: 1, b: -1, c: 1});
// Test equality - all indexed fields queried and projected
var plan = coll.find({a: 10, b: "strvar_10", c: 0}, {a: 1, b: 1, c: 1, _id: 0})
diff --git a/jstests/core/covered_index_negative_1.js b/jstests/core/covered_index_negative_1.js
index 06d4119ffe4..4028b1159b2 100644
--- a/jstests/core/covered_index_negative_1.js
+++ b/jstests/core/covered_index_negative_1.js
@@ -16,10 +16,10 @@ for (i = 0; i < 100; i++) {
coll.insert(
{a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10), d: i * 10, e: [i, i % 10], f: i});
}
-coll.createIndex({a: 1, b: -1, c: 1});
-coll.createIndex({e: 1});
-coll.createIndex({d: 1});
-coll.createIndex({f: "hashed"});
+coll.ensureIndex({a: 1, b: -1, c: 1});
+coll.ensureIndex({e: 1});
+coll.ensureIndex({d: 1});
+coll.ensureIndex({f: "hashed"});
// Test no projection
var plan =
diff --git a/jstests/core/covered_index_simple_1.js b/jstests/core/covered_index_simple_1.js
index ce8f1978a89..c49e5a2bc8e 100644
--- a/jstests/core/covered_index_simple_1.js
+++ b/jstests/core/covered_index_simple_1.js
@@ -25,7 +25,7 @@ for (i = 0; i < 5; i++) {
coll.insert({foo: "string"});
coll.insert({foo: {bar: 1}});
coll.insert({foo: null});
-coll.createIndex({foo: 1});
+coll.ensureIndex({foo: 1});
// Test equality with int value
var plan = coll.find({foo: 1}, {foo: 1, _id: 0}).hint({foo: 1}).explain("executionStats");
diff --git a/jstests/core/covered_index_simple_2.js b/jstests/core/covered_index_simple_2.js
index 066bf1bae4c..67548ed8c06 100644
--- a/jstests/core/covered_index_simple_2.js
+++ b/jstests/core/covered_index_simple_2.js
@@ -19,7 +19,7 @@ for (i = 0; i < 10; i++) {
coll.insert({foo: "string"});
coll.insert({foo: {bar: 1}});
coll.insert({foo: null});
-coll.createIndex({foo: 1}, {unique: true});
+coll.ensureIndex({foo: 1}, {unique: true});
// Test equality with int value
var plan = coll.find({foo: 1}, {foo: 1, _id: 0}).hint({foo: 1}).explain("executionStats");
diff --git a/jstests/core/covered_index_simple_3.js b/jstests/core/covered_index_simple_3.js
index c0e62a9243d..5e654475252 100644
--- a/jstests/core/covered_index_simple_3.js
+++ b/jstests/core/covered_index_simple_3.js
@@ -22,7 +22,7 @@ for (i = 0; i < 5; i++) {
coll.insert({foo: "string"});
coll.insert({foo: {bar: 1}});
coll.insert({foo: null});
-coll.createIndex({foo: 1}, {sparse: true, unique: true});
+coll.ensureIndex({foo: 1}, {sparse: true, unique: true});
// Test equality with int value
var plan = coll.find({foo: 1}, {foo: 1, _id: 0}).hint({foo: 1}).explain("executionStats");
@@ -85,7 +85,7 @@ assert.eq(0,
// Check that $nin can be covered.
coll.dropIndexes();
-coll.createIndex({bar: 1});
+coll.ensureIndex({bar: 1});
var plan =
coll.find({bar: {$nin: [5, 8]}}, {bar: 1, _id: 0}).hint({bar: 1}).explain("executionStats");
assert(isIndexOnly(db, plan.queryPlanner.winningPlan),
diff --git a/jstests/core/covered_index_sort_1.js b/jstests/core/covered_index_sort_1.js
index 526ddfbaa42..4b8cea2e825 100644
--- a/jstests/core/covered_index_sort_1.js
+++ b/jstests/core/covered_index_sort_1.js
@@ -25,7 +25,7 @@ for (i = 0; i < 5; i++) {
coll.insert({foo: "1"});
coll.insert({foo: {bar: 1}});
coll.insert({foo: null});
-coll.createIndex({foo: 1});
+coll.ensureIndex({foo: 1});
// Test no query and sort ascending
var plan = coll.find({}, {foo: 1, _id: 0}).sort({foo: 1}).hint({foo: 1}).explain("executionStats");
diff --git a/jstests/core/covered_index_sort_3.js b/jstests/core/covered_index_sort_3.js
index 0e9b1ea30ff..1107e0584dc 100644
--- a/jstests/core/covered_index_sort_3.js
+++ b/jstests/core/covered_index_sort_3.js
@@ -17,7 +17,7 @@ for (i = 0; i < 100; i++) {
coll.insert({a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10)});
}
-coll.createIndex({a: 1, b: -1, c: 1});
+coll.ensureIndex({a: 1, b: -1, c: 1});
// Test no query, sort on all fields in index order
var plan = coll.find({}, {b: 1, c: 1, _id: 0})
diff --git a/jstests/core/create_index_helper_validation.js b/jstests/core/create_index_helper_validation.js
index 1b11a50c6ca..805c567316d 100644
--- a/jstests/core/create_index_helper_validation.js
+++ b/jstests/core/create_index_helper_validation.js
@@ -20,7 +20,7 @@ assert.throws(() => coll.createIndex(
{background: true},
{unique: true}));
-assert.throws(() => coll.createIndex(
+assert.throws(() => coll.ensureIndex(
/* keys */ {a: 1},
/* options */ {},
/* commitQuorum */ "majority",
diff --git a/jstests/core/crud_api.js b/jstests/core/crud_api.js
index 9eb09ab6436..4b37300e9b1 100644
--- a/jstests/core/crud_api.js
+++ b/jstests/core/crud_api.js
@@ -700,7 +700,7 @@ var crudAPISpecTests = function crudAPISpecTests() {
// Drop collection
coll.drop();
- coll.createIndex({a: 1}, {unique: true});
+ coll.ensureIndex({a: 1}, {unique: true});
// Should throw duplicate key error
assert.throws(function() {
diff --git a/jstests/core/cursor3.js b/jstests/core/cursor3.js
index f416ec47931..1a7e0dfcc7e 100644
--- a/jstests/core/cursor3.js
+++ b/jstests/core/cursor3.js
@@ -23,7 +23,7 @@ t.save({a: 0});
t.save({a: 1});
t.save({a: 2});
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
checkResults([1], t.find({a: 1}).sort({a: 1}).hint({a: 1}), testNum++);
checkResults([1], t.find({a: 1}).sort({a: -1}).hint({a: 1}), testNum++);
diff --git a/jstests/core/cursor4.js b/jstests/core/cursor4.js
index d0440d329f1..dd7875d0836 100644
--- a/jstests/core/cursor4.js
+++ b/jstests/core/cursor4.js
@@ -15,7 +15,7 @@ function testConstrainedFindMultiFieldSorting(db) {
entries = [{a: 0, b: 0}, {a: 0, b: 1}, {a: 1, b: 1}, {a: 1, b: 1}, {a: 2, b: 0}];
for (i = 0; i < entries.length; ++i)
r.save(entries[i]);
- r.createIndex({a: 1, b: 1});
+ r.ensureIndex({a: 1, b: 1});
reverseEntries = entries.slice();
reverseEntries.reverse();
diff --git a/jstests/core/cursor5.js b/jstests/core/cursor5.js
index aab03473255..0232b92e4cc 100644
--- a/jstests/core/cursor5.js
+++ b/jstests/core/cursor5.js
@@ -26,7 +26,7 @@ function testBoundsWithSubobjectIndexes(db) {
r.save(z[i]);
idx = {"a.d": 1, a: 1, e: -1};
rIdx = {"a.d": -1, a: -1, e: 1};
- r.createIndex(idx);
+ r.ensureIndex(idx);
checkResults([z[0], z[4], z[2]], r.find({e: 4}).sort(idx).hint(idx));
checkResults([z[1], z[3]], r.find({e: {$gt: 4}, "a.b": 1}).sort(idx).hint(idx));
diff --git a/jstests/core/cursor6.js b/jstests/core/cursor6.js
index 7c8daa1bfcb..d2c56c00e75 100644
--- a/jstests/core/cursor6.js
+++ b/jstests/core/cursor6.js
@@ -60,7 +60,7 @@ z = [{a: 1, b: 1}, {a: 1, b: 2}, {a: 2, b: 1}, {a: 2, b: 2}];
for (i = 0; i < z.length; ++i)
r.save(z[i]);
-r.createIndex({a: 1, b: -1});
+r.ensureIndex({a: 1, b: -1});
check(false);
check(true);
diff --git a/jstests/core/cursor7.js b/jstests/core/cursor7.js
index 4a21c420274..7807dbe22f5 100644
--- a/jstests/core/cursor7.js
+++ b/jstests/core/cursor7.js
@@ -17,7 +17,7 @@ function testMultipleInequalities(db) {
r.save(z[i]);
idx = {a: 1, b: 1};
rIdx = {a: -1, b: -1};
- r.createIndex(idx);
+ r.ensureIndex(idx);
checkResults([z[2], z[3]], r.find({a: {$gt: 3}}).sort(idx).hint(idx));
checkResults([z[2]], r.find({a: {$gt: 3, $lt: 7}}).sort(idx).hint(idx));
diff --git a/jstests/core/date2.js b/jstests/core/date2.js
index a398058d771..15993815b14 100644
--- a/jstests/core/date2.js
+++ b/jstests/core/date2.js
@@ -3,7 +3,7 @@
t = db.jstests_date2;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
var obj = {a: new Timestamp(0, 1)}; // in old versions this was == to new Date(1)
t.save(obj);
diff --git a/jstests/core/date3.js b/jstests/core/date3.js
index e3eaea620ec..80279a9559c 100644
--- a/jstests/core/date3.js
+++ b/jstests/core/date3.js
@@ -29,5 +29,5 @@ function test() {
}
test();
-t.createIndex({d: 1});
+t.ensureIndex({d: 1});
test();
diff --git a/jstests/core/distinct3.js b/jstests/core/distinct3.js
index 6a67635500d..654cd8e352a 100644
--- a/jstests/core/distinct3.js
+++ b/jstests/core/distinct3.js
@@ -10,8 +10,8 @@
t = db.jstests_distinct3;
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
var bulk = t.initializeUnorderedBulkOp();
for (i = 0; i < 50; ++i) {
diff --git a/jstests/core/distinct_array1.js b/jstests/core/distinct_array1.js
index cb82c25bbff..2d3a96a6af6 100644
--- a/jstests/core/distinct_array1.js
+++ b/jstests/core/distinct_array1.js
@@ -19,7 +19,7 @@ res = t.distinct("a.1").sort();
assert.eq("2,3,4", res.toString());
// With index.
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
res = t.distinct("a").sort();
assert.eq("1,2,3,4,5,9", res.toString());
@@ -51,7 +51,7 @@ res = t.distinct("a.1.b").sort();
assert.eq("d,e,f", res.toString());
// With index.
-t.createIndex({"a.b": 1});
+t.ensureIndex({"a.b": 1});
res = t.distinct("a.b");
res.sort();
// TODO SERVER-14832 The presence of an index may change results, but only if the index is not
@@ -85,7 +85,7 @@ res = t.distinct("_id.a.1").sort();
assert.eq("2,3,4", res.toString());
// With index.
-t.createIndex({"_id.a": 1});
+t.ensureIndex({"_id.a": 1});
res = t.distinct("_id.a").sort();
// TODO SERVER-14832: distinct() may incorrectly return null in presence of index.
assert.eq([1, 2, 3, 4, 5, 9, null], res);
diff --git a/jstests/core/distinct_index2.js b/jstests/core/distinct_index2.js
index 1f552102059..d1b72565102 100644
--- a/jstests/core/distinct_index2.js
+++ b/jstests/core/distinct_index2.js
@@ -1,8 +1,8 @@
t = db.distinct_index2;
t.drop();
-t.createIndex({a: 1, b: 1});
-t.createIndex({c: 1});
+t.ensureIndex({a: 1, b: 1});
+t.ensureIndex({c: 1});
// Uniformly distributed dataset.
// If we use a randomly generated dataset, we might not
@@ -37,5 +37,5 @@ check("c");
// hashed index should produce same results.
t.dropIndexes();
-t.createIndex({a: "hashed"});
+t.ensureIndex({a: "hashed"});
check("a");
diff --git a/jstests/core/drop.js b/jstests/core/drop.js
index 769a8cd348c..ea395660a5f 100644
--- a/jstests/core/drop.js
+++ b/jstests/core/drop.js
@@ -12,12 +12,12 @@ assert(!res.ok, tojson(res));
assert.eq(0, coll.getIndexes().length, "A");
coll.save({});
assert.eq(1, coll.getIndexes().length, "B");
-coll.createIndex({a: 1});
+coll.ensureIndex({a: 1});
assert.eq(2, coll.getIndexes().length, "C");
assert.commandWorked(db.runCommand({drop: coll.getName()}));
assert.eq(0, coll.getIndexes().length, "D");
-coll.createIndex({a: 1});
+coll.ensureIndex({a: 1});
assert.eq(2, coll.getIndexes().length, "E");
assert.commandWorked(db.runCommand({dropIndexes: coll.getName(), index: "*"}), "drop indexes A");
assert.eq(1, coll.getIndexes().length, "G");
diff --git a/jstests/core/drop_index.js b/jstests/core/drop_index.js
index e808b1f7829..60dbec0e3ea 100644
--- a/jstests/core/drop_index.js
+++ b/jstests/core/drop_index.js
@@ -57,7 +57,7 @@ assert.commandFailedWithCode(t.dropIndex({_id: 1}), ErrorCodes.InvalidOptions);
// Ensure you can recreate indexes, even if you don't use dropIndex method.
// Prior to SERVER-7168, the shell used to cache names of indexes created using
-// Collection.createIndex().
+// Collection.ensureIndex().
assert.commandWorked(t.createIndex({a: 1}));
assertIndexes(['a_1', 'c_1', 'd_1', 'e_1'], 'recreating {a: 1}');
diff --git a/jstests/core/dropdb_race.js b/jstests/core/dropdb_race.js
index 8f1356db1d6..6bcd334e7ab 100644
--- a/jstests/core/dropdb_race.js
+++ b/jstests/core/dropdb_race.js
@@ -25,7 +25,7 @@ for (var pass = 0; pass < 100; pass++) {
}
t.insert({x: 1});
t.insert({x: 3});
- t.createIndex({x: 1});
+ t.ensureIndex({x: 1});
sleep(s);
if (pass % 13 == 0)
t.drop();
diff --git a/jstests/core/exists.js b/jstests/core/exists.js
index b85d80c36a7..e0ba49fabd8 100644
--- a/jstests/core/exists.js
+++ b/jstests/core/exists.js
@@ -36,10 +36,10 @@ function dotest(n) {
}
dotest("before index");
-t.createIndex({"a": 1});
-t.createIndex({"a.b": 1});
-t.createIndex({"a.b.c": 1});
-t.createIndex({"a.b.c.d": 1});
+t.ensureIndex({"a": 1});
+t.ensureIndex({"a.b": 1});
+t.ensureIndex({"a.b.c": 1});
+t.ensureIndex({"a.b.c.d": 1});
dotest("after index");
assert.eq(1, t.find({a: {$exists: false}}).hint({a: 1}).itcount());
diff --git a/jstests/core/exists2.js b/jstests/core/exists2.js
index 0764d859c3b..3b4580cd310 100644
--- a/jstests/core/exists2.js
+++ b/jstests/core/exists2.js
@@ -9,6 +9,6 @@ assert.eq(2, t.find({a: 1, b: 1}).itcount(), "A2");
assert.eq(1, t.find({a: 1, b: 1, c: {"$exists": true}}).itcount(), "A3");
assert.eq(1, t.find({a: 1, b: 1, c: {"$exists": false}}).itcount(), "A4");
-t.createIndex({a: 1, b: 1, c: 1});
+t.ensureIndex({a: 1, b: 1, c: 1});
assert.eq(1, t.find({a: 1, b: 1, c: {"$exists": true}}).itcount(), "B1");
assert.eq(1, t.find({a: 1, b: 1, c: {"$exists": false}}).itcount(), "B2");
diff --git a/jstests/core/exists3.js b/jstests/core/exists3.js
index 510d63c3752..e4ce03437bb 100644
--- a/jstests/core/exists3.js
+++ b/jstests/core/exists3.js
@@ -11,7 +11,7 @@ assert.eq(1, t.find({c: {$exists: false}}).itcount());
assert.eq(1, t.find({c: {$exists: false}}).sort({c: -1}).itcount());
// now we have an index on the sort key
-t.createIndex({c: -1});
+t.ensureIndex({c: -1});
assert.eq(1, t.find({c: {$exists: false}}).sort({c: -1}).itcount());
assert.eq(1, t.find({c: {$exists: false}}).itcount());
diff --git a/jstests/core/exists4.js b/jstests/core/exists4.js
index a533ca53e9c..2979a60f276 100644
--- a/jstests/core/exists4.js
+++ b/jstests/core/exists4.js
@@ -3,7 +3,7 @@
t = db.jstests_exists4;
t.drop();
-t.createIndex({date: -1, country_code: 1, user_id: 1}, {unique: 1, background: 1});
+t.ensureIndex({date: -1, country_code: 1, user_id: 1}, {unique: 1, background: 1});
t.insert({date: new Date("08/27/2010"), tot_visit: 100});
t.insert({date: new Date("08/27/2010"), country_code: "IT", tot_visit: 77});
t.insert({date: new Date("08/27/2010"), country_code: "ES", tot_visit: 23});
diff --git a/jstests/core/exists6.js b/jstests/core/exists6.js
index 736574db895..67ab7e5345d 100644
--- a/jstests/core/exists6.js
+++ b/jstests/core/exists6.js
@@ -3,7 +3,7 @@
t = db.jstests_exists6;
t.drop();
-t.createIndex({b: 1});
+t.ensureIndex({b: 1});
t.save({});
t.save({b: 1});
t.save({b: null});
@@ -14,7 +14,7 @@ assert.eq(1, t.find({b: {$exists: false}}).itcount());
assert.eq(1, t.find({b: {$not: {$exists: true}}}).itcount());
// Now check existence of second compound field.
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
t.save({a: 1});
t.save({a: 1, b: 1});
t.save({a: 1, b: null});
diff --git a/jstests/core/exists7.js b/jstests/core/exists7.js
index 6ca55a42286..74ea4e9719c 100644
--- a/jstests/core/exists7.js
+++ b/jstests/core/exists7.js
@@ -18,5 +18,5 @@ function testIntegerExistsSpec() {
}
testIntegerExistsSpec();
-t.createIndex({b: 1});
+t.ensureIndex({b: 1});
testIntegerExistsSpec();
diff --git a/jstests/core/exists9.js b/jstests/core/exists9.js
index 3b245cd4188..444bcf731a1 100644
--- a/jstests/core/exists9.js
+++ b/jstests/core/exists9.js
@@ -12,7 +12,7 @@ assert.eq(1, t.count({'a.b': {$exists: false}}));
assert.eq(0, t.count({'a.b': {$exists: true}}));
// With index.
-t.createIndex({'a.b': 1});
+t.ensureIndex({'a.b': 1});
assert.eq(1, t.find({'a.b': {$exists: false}}).hint({'a.b': 1}).itcount());
assert.eq(0, t.find({'a.b': {$exists: true}}).hint({'a.b': 1}).itcount());
@@ -25,7 +25,7 @@ assert.eq(1, t.count({a: {$exists: true}}));
assert.eq(1, t.count({a: {$exists: false}}));
// With index.
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq(1, t.find({a: {$exists: true}}).hint({a: 1}).itcount());
assert.eq(1, t.find({a: {$exists: false}}).hint({a: 1}).itcount());
@@ -38,6 +38,6 @@ assert.eq(1, t.count({'a.0': {$exists: true}}));
assert.eq(1, t.count({'a.0': {$exists: false}}));
// With index.
-t.createIndex({'a.0': 1});
+t.ensureIndex({'a.0': 1});
assert.eq(1, t.find({'a.0': {$exists: true}}).hint({'a.0': 1}).itcount());
assert.eq(1, t.find({'a.0': {$exists: false}}).hint({'a.0': 1}).itcount());
diff --git a/jstests/core/existsa.js b/jstests/core/existsa.js
index 2b5f70dd77f..d1079310d71 100644
--- a/jstests/core/existsa.js
+++ b/jstests/core/existsa.js
@@ -19,7 +19,7 @@ function setIndex(_indexKeyField) {
indexKeyField = _indexKeyField;
indexKeySpec = {};
indexKeySpec[indexKeyField] = 1;
- coll.createIndex(indexKeySpec, {sparse: true});
+ coll.ensureIndex(indexKeySpec, {sparse: true});
}
setIndex('a');
@@ -106,6 +106,6 @@ assertExistsUnindexed({'a.b': {$elemMatch: {$gt: 0, $not: {$exists: false}}}}, 1
// A non sparse index will not be disallowed.
coll.drop();
assert.commandWorked(coll.insert({}));
-coll.createIndex({a: 1});
+coll.ensureIndex({a: 1});
assert.eq(1, coll.find({a: {$exists: false}}).itcount());
})();
diff --git a/jstests/core/existsb.js b/jstests/core/existsb.js
index 64ee3cf9a88..d46266cdd16 100644
--- a/jstests/core/existsb.js
+++ b/jstests/core/existsb.js
@@ -57,20 +57,20 @@ function checkExistsNull() {
checkExistsNull();
// try with a standard index
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
checkExistsNull();
// try with a sparse index
t.dropIndexes();
-t.createIndex({a: 1}, {sparse: true});
+t.ensureIndex({a: 1}, {sparse: true});
checkExistsNull();
// try with a compound index
t.dropIndexes();
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
checkExistsNull();
// try with sparse compound index
t.dropIndexes();
-t.createIndex({a: 1, b: 1}, {sparse: true});
+t.ensureIndex({a: 1, b: 1}, {sparse: true});
checkExistsNull();
diff --git a/jstests/core/explain1.js b/jstests/core/explain1.js
index 8450335159d..09891f214dd 100644
--- a/jstests/core/explain1.js
+++ b/jstests/core/explain1.js
@@ -19,7 +19,7 @@ assert.eq(49, t.find(q).count(), "A");
assert.eq(49, t.find(q).itcount(), "B");
assert.eq(20, t.find(q).limit(20).itcount(), "C");
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq(49, t.find(q).count(), "D");
assert.eq(49, t.find(q).itcount(), "E");
diff --git a/jstests/core/explain4.js b/jstests/core/explain4.js
index df0d98382e0..06c7bf0b359 100644
--- a/jstests/core/explain4.js
+++ b/jstests/core/explain4.js
@@ -6,7 +6,7 @@
t = db.jstests_explain4;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
for (i = 0; i < 10; ++i) {
t.save({a: i, b: 0});
diff --git a/jstests/core/explain5.js b/jstests/core/explain5.js
index 50648cd8817..5bae866e096 100644
--- a/jstests/core/explain5.js
+++ b/jstests/core/explain5.js
@@ -7,8 +7,8 @@
t = db.jstests_explain5;
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
for (i = 0; i < 1000; ++i) {
t.save({a: i, b: i % 3});
diff --git a/jstests/core/explain6.js b/jstests/core/explain6.js
index f36640ce567..dbbb767531c 100644
--- a/jstests/core/explain6.js
+++ b/jstests/core/explain6.js
@@ -10,8 +10,8 @@
t = db.jstests_explain6;
t.drop();
-t.createIndex({a: 1, b: 1});
-t.createIndex({b: 1, a: 1});
+t.ensureIndex({a: 1, b: 1});
+t.ensureIndex({b: 1, a: 1});
t.save({a: 0, b: 1});
t.save({a: 1, b: 0});
diff --git a/jstests/core/explain_count.js b/jstests/core/explain_count.js
index 8dc0854ab15..883f8b84ac7 100644
--- a/jstests/core/explain_count.js
+++ b/jstests/core/explain_count.js
@@ -99,7 +99,7 @@ assertExplainCount({explainResults: explain, expectedCount: 0});
// Now add a bit of data to the collection.
// On sharded clusters, we'll want the shard key to be indexed, so we make _id part of the index.
// This means counts will not have to fetch from the document in order to get the shard key.
-t.createIndex({a: 1, _id: 1});
+t.ensureIndex({a: 1, _id: 1});
for (var i = 0; i < 10; i++) {
t.insert({_id: i, a: 1});
}
diff --git a/jstests/core/explain_delete.js b/jstests/core/explain_delete.js
index 44a67ea21ca..1863979faa5 100644
--- a/jstests/core/explain_delete.js
+++ b/jstests/core/explain_delete.js
@@ -43,7 +43,7 @@ explain = db.runCommand({explain: {delete: collName, deletes: [{q: {a: 1}, limit
checkNWouldDelete(explain, 0);
// Add an index but no data, and check that the explain still works.
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
explain = db.runCommand({explain: {delete: collName, deletes: [{q: {a: 1}, limit: 0}]}});
checkNWouldDelete(explain, 0);
diff --git a/jstests/core/explain_execution_error.js b/jstests/core/explain_execution_error.js
index 4515a050edc..d2240452573 100644
--- a/jstests/core/explain_execution_error.js
+++ b/jstests/core/explain_execution_error.js
@@ -117,8 +117,8 @@ assertExecError(result);
// Now we introduce two indices. One provides the requested sort order, and
// the other does not.
-t.createIndex({b: 1});
-t.createIndex({c: 1});
+t.ensureIndex({b: 1});
+t.ensureIndex({c: 1});
// The query should no longer fail with a memory limit error because the planner can obtain
// the sort by scanning an index.
diff --git a/jstests/core/explain_find.js b/jstests/core/explain_find.js
index c42d59d7671..fcf2e35053c 100644
--- a/jstests/core/explain_find.js
+++ b/jstests/core/explain_find.js
@@ -10,7 +10,7 @@ var collName = "jstests_explain_find";
var t = db[collName];
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
for (var i = 0; i < 10; i++) {
t.insert({_id: i, a: i});
diff --git a/jstests/core/explain_large_bounds.js b/jstests/core/explain_large_bounds.js
index 1ca27f9a8ef..1ff7307e7d9 100644
--- a/jstests/core/explain_large_bounds.js
+++ b/jstests/core/explain_large_bounds.js
@@ -8,7 +8,7 @@
const coll = db.jstests_explain_large_bounds;
coll.drop();
-coll.createIndex({a: 1});
+coll.ensureIndex({a: 1});
let inClause = [];
for (let i = 0; i < 1000000; i++) {
diff --git a/jstests/core/explain_multi_plan.js b/jstests/core/explain_multi_plan.js
index 845438af91e..dc8f153e6cb 100644
--- a/jstests/core/explain_multi_plan.js
+++ b/jstests/core/explain_multi_plan.js
@@ -16,8 +16,8 @@ var coll = db.explainMultiPlan;
coll.drop();
// Create indices to ensure there are multiple plans available.
-assert.commandWorked(coll.createIndex({a: 1, b: 1}));
-assert.commandWorked(coll.createIndex({a: 1, b: -1}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: -1}));
// Insert some data to work with.
var bulk = coll.initializeOrderedBulkOp();
diff --git a/jstests/core/explain_shell_helpers.js b/jstests/core/explain_shell_helpers.js
index cad5fec9141..1a66a032143 100644
--- a/jstests/core/explain_shell_helpers.js
+++ b/jstests/core/explain_shell_helpers.js
@@ -22,7 +22,7 @@ load("jstests/libs/analyze_plan.js");
var explain;
var stage;
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
for (var i = 0; i < 10; i++) {
t.insert({_id: i, a: i, b: 1});
}
@@ -267,7 +267,7 @@ assert(planHasStage(db, explain.queryPlanner.winningPlan, "COUNT"));
assert(planHasStage(db, explain.queryPlanner.winningPlan, "COUNT_SCAN"));
// Explainable count with hint.
-assert.commandWorked(t.createIndex({c: 1}, {sparse: true}));
+assert.commandWorked(t.ensureIndex({c: 1}, {sparse: true}));
explain = t.explain().count({c: {$exists: false}}, {hint: "c_1"});
assert.commandWorked(explain);
assert(planHasStage(db, explain.queryPlanner.winningPlan, "IXSCAN"));
diff --git a/jstests/core/expr.js b/jstests/core/expr.js
index a6861a4d2cf..1a23ac00d8b 100644
--- a/jstests/core/expr.js
+++ b/jstests/core/expr.js
@@ -190,7 +190,7 @@ if (db.getMongo().writeMode() === "commands") {
coll.drop();
assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, a: 0}));
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}));
assert.eq(1,
coll.aggregate({
$geoNear: {
diff --git a/jstests/core/filemd5.js b/jstests/core/filemd5.js
index 064bf323bcf..b33611c1e90 100644
--- a/jstests/core/filemd5.js
+++ b/jstests/core/filemd5.js
@@ -17,7 +17,7 @@ assert.commandWorked(db.fs.chunks.insert({files_id: 1, n: 0, data: new BinData(0
assert.commandFailedWithCode(db.runCommand({filemd5: 1, root: "fs"}),
ErrorCodes.NoQueryExecutionPlans);
-db.fs.chunks.createIndex({files_id: 1, n: 1});
+db.fs.chunks.ensureIndex({files_id: 1, n: 1});
assert.commandWorked(db.runCommand({filemd5: 1, root: "fs"}));
assert.commandFailedWithCode(db.runCommand({filemd5: 1, root: "fs", partialOk: 1, md5state: 5}),
diff --git a/jstests/core/find6.js b/jstests/core/find6.js
index 4c7a0a9384b..7edf1739c78 100644
--- a/jstests/core/find6.js
+++ b/jstests/core/find6.js
@@ -34,7 +34,7 @@ function f() {
for (var pass = 0; pass <= 1; pass++) {
f();
- q.createIndex({a: 1});
+ q.ensureIndex({a: 1});
}
t = db.multidim;
diff --git a/jstests/core/find_and_modify_concurrent_update.js b/jstests/core/find_and_modify_concurrent_update.js
index dca7c547c18..f1ac1282b49 100644
--- a/jstests/core/find_and_modify_concurrent_update.js
+++ b/jstests/core/find_and_modify_concurrent_update.js
@@ -19,8 +19,8 @@ for (var i = 0; i < 3; i++) {
var t = db.find_and_modify_concurrent;
t.drop();
- assert.commandWorked(t.createIndex({a: 1}));
- assert.commandWorked(t.createIndex({b: 1}));
+ assert.commandWorked(t.ensureIndex({a: 1}));
+ assert.commandWorked(t.ensureIndex({b: 1}));
assert.commandWorked(t.insert({_id: 1, a: 1, b: 1}));
var join =
diff --git a/jstests/core/find_dedup.js b/jstests/core/find_dedup.js
index 8c0f416efb1..8c628b66734 100644
--- a/jstests/core/find_dedup.js
+++ b/jstests/core/find_dedup.js
@@ -22,7 +22,7 @@ function checkDedup(query, idArray) {
// Deduping $or
coll.drop();
-coll.createIndex({a: 1, b: 1});
+coll.ensureIndex({a: 1, b: 1});
assert.commandWorked(coll.insert({_id: 1, a: 1, b: 1}));
assert.commandWorked(coll.insert({_id: 2, a: 1, b: 1}));
assert.commandWorked(coll.insert({_id: 3, a: 2, b: 2}));
diff --git a/jstests/core/finda.js b/jstests/core/finda.js
index 1525c7aaeda..0f59c4c7f3b 100644
--- a/jstests/core/finda.js
+++ b/jstests/core/finda.js
@@ -11,7 +11,7 @@ t.drop();
numDocs = 200;
function clearQueryPlanCache() {
- t.createIndex({c: 1});
+ t.ensureIndex({c: 1});
t.dropIndex({c: 1});
}
@@ -92,7 +92,7 @@ function queryWithPlanTypes(withDups) {
} else {
t.save({_id: 0, a: 0, b: 0});
}
- t.createIndex({a: 1, _id: 1}); // Include _id for a covered index projection.
+ t.ensureIndex({a: 1, _id: 1}); // Include _id for a covered index projection.
// All plans in order.
checkCursorWithBatchSize({a: {$gte: 0}}, null, 150, 150);
diff --git a/jstests/core/fts2.js b/jstests/core/fts2.js
index 7629d313b00..77b6fe25bd5 100644
--- a/jstests/core/fts2.js
+++ b/jstests/core/fts2.js
@@ -12,7 +12,7 @@ t.drop();
t.save({_id: 1, x: "az b x", y: "c d m", z: 1});
t.save({_id: 2, x: "c d y", y: "az b n", z: 2});
-t.createIndex({x: "text"}, {weights: {x: 10, y: 1}});
+t.ensureIndex({x: "text"}, {weights: {x: 10, y: 1}});
assert.eq([1, 2], queryIDS(t, "az"), "A1");
assert.eq([2, 1], queryIDS(t, "d"), "A2");
diff --git a/jstests/core/fts3.js b/jstests/core/fts3.js
index 32aa3fb002a..6a4c813744a 100644
--- a/jstests/core/fts3.js
+++ b/jstests/core/fts3.js
@@ -12,7 +12,7 @@ t.drop();
t.save({_id: 1, x: "az b x", y: "c d m", z: 1});
t.save({_id: 2, x: "c d y", y: "az b n", z: 2});
-t.createIndex({x: "text", z: 1}, {weights: {x: 10, y: 1}});
+t.ensureIndex({x: "text", z: 1}, {weights: {x: 10, y: 1}});
assert.eq([1, 2], queryIDS(t, "az"), "A1");
assert.eq([2, 1], queryIDS(t, "d"), "A2");
diff --git a/jstests/core/fts4.js b/jstests/core/fts4.js
index ea8055eeb11..16f88a7a760 100644
--- a/jstests/core/fts4.js
+++ b/jstests/core/fts4.js
@@ -12,7 +12,7 @@ t.drop();
t.save({_id: 1, x: ["az", "b", "x"], y: ["c", "d", "m"], z: 1});
t.save({_id: 2, x: ["c", "d", "y"], y: ["az", "b", "n"], z: 2});
-t.createIndex({y: "text", z: 1}, {weights: {x: 10}});
+t.ensureIndex({y: "text", z: 1}, {weights: {x: 10}});
assert.eq([1, 2], queryIDS(t, "az"), "A1");
assert.eq([2, 1], queryIDS(t, "d"), "A2");
diff --git a/jstests/core/fts5.js b/jstests/core/fts5.js
index aa689a46ed9..99cd6ce84bb 100644
--- a/jstests/core/fts5.js
+++ b/jstests/core/fts5.js
@@ -12,7 +12,7 @@ t.drop();
t.save({_id: 1, x: [{a: "az"}, {a: "b"}, {a: "x"}], y: ["c", "d", "m"], z: 1});
t.save({_id: 2, x: [{a: "c"}, {a: "d"}, {a: "y"}], y: ["az", "b", "n"], z: 2});
-t.createIndex({y: "text", z: 1}, {weights: {"x.a": 10}});
+t.ensureIndex({y: "text", z: 1}, {weights: {"x.a": 10}});
assert.eq([1, 2], queryIDS(t, "az"), "A1");
assert.eq([2, 1], queryIDS(t, "d"), "A2");
diff --git a/jstests/core/fts6.js b/jstests/core/fts6.js
index ab757b81d59..7216fc728e9 100644
--- a/jstests/core/fts6.js
+++ b/jstests/core/fts6.js
@@ -7,8 +7,8 @@
var t = db.jstests_fts6;
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: "text"});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: "text"});
t.save({_id: 1, a: 0});
t.save({_id: 2, a: 0, b: "foo"});
diff --git a/jstests/core/fts_blog.js b/jstests/core/fts_blog.js
index 2b0fe26e095..cdaba7860fc 100644
--- a/jstests/core/fts_blog.js
+++ b/jstests/core/fts_blog.js
@@ -10,7 +10,7 @@ t.save({_id: 3, title: "knives are Fun", text: "this is a new blog i am writing.
// @tags: [
// sbe_incompatible,
// ]
-t.createIndex({"title": "text", text: "text"}, {weights: {title: 10}});
+t.ensureIndex({"title": "text", text: "text"}, {weights: {title: 10}});
res = t.find({"$text": {"$search": "blog"}}, {score: {"$meta": "textScore"}}).sort({
score: {"$meta": "textScore"}
diff --git a/jstests/core/fts_blogwild.js b/jstests/core/fts_blogwild.js
index 881c486edad..207fea471c1 100644
--- a/jstests/core/fts_blogwild.js
+++ b/jstests/core/fts_blogwild.js
@@ -18,7 +18,7 @@ t.save({
// default weight is 1
// specify weights if you want a field to be more meaningull
-t.createIndex({dummy: "text"}, {weights: "$**"});
+t.ensureIndex({dummy: "text"}, {weights: "$**"});
res = t.find({"$text": {"$search": "blog"}});
assert.eq(3, res.length(), "A1");
@@ -29,7 +29,7 @@ assert.eq(3, res.length(), "B1");
// mixing
t.dropIndex("dummy_text");
assert.eq(1, t.getIndexKeys().length, "C1");
-t.createIndex({dummy: "text"}, {weights: {"$**": 1, title: 2}});
+t.ensureIndex({dummy: "text"}, {weights: {"$**": 1, title: 2}});
res = t.find({"$text": {"$search": "write"}}, {score: {"$meta": "textScore"}}).sort({
score: {"$meta": "textScore"}
diff --git a/jstests/core/fts_casesensitive.js b/jstests/core/fts_casesensitive.js
index b4a730a46b5..191631a6ac0 100644
--- a/jstests/core/fts_casesensitive.js
+++ b/jstests/core/fts_casesensitive.js
@@ -9,7 +9,7 @@ var coll = db.fts_casesensitive;
coll.drop();
assert.commandWorked(coll.insert({_id: 0, a: "The Quick Brown Fox Jumps Over The Lazy Dog"}));
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
assert.throws(function() {
queryIDS(coll, "hello", null, {$caseSensitive: "invalid"});
diff --git a/jstests/core/fts_diacritic_and_caseinsensitive.js b/jstests/core/fts_diacritic_and_caseinsensitive.js
index 1b8a2d0d1e0..107ff447ec9 100644
--- a/jstests/core/fts_diacritic_and_caseinsensitive.js
+++ b/jstests/core/fts_diacritic_and_caseinsensitive.js
@@ -14,7 +14,7 @@ coll.drop();
assert.commandWorked(coll.insert(
{_id: 0, a: "O próximo Vôo à Noite sobre o Atlântico, Põe Freqüentemente o único Médico."}));
-assert.commandWorked(coll.createIndex({a: "text"}, {default_language: "portuguese"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {default_language: "portuguese"}));
assert.eq([0], queryIDS(coll, "proximo voo a", null));
assert.eq([0], queryIDS(coll, "átlántico", null));
diff --git a/jstests/core/fts_diacritic_and_casesensitive.js b/jstests/core/fts_diacritic_and_casesensitive.js
index 124ec9c092d..0f0e63feca4 100644
--- a/jstests/core/fts_diacritic_and_casesensitive.js
+++ b/jstests/core/fts_diacritic_and_casesensitive.js
@@ -15,7 +15,7 @@ coll.drop();
assert.commandWorked(coll.insert(
{_id: 0, a: "O próximo Vôo à Noite sobre o Atlântico, Põe Freqüentemente o único Médico."}));
-assert.commandWorked(coll.createIndex({a: "text"}, {default_language: "portuguese"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {default_language: "portuguese"}));
assert.eq([0],
queryIDS(coll, "próximo vôo à", null, {$diacriticSensitive: true, $caseSensitive: true}));
diff --git a/jstests/core/fts_diacriticsensitive.js b/jstests/core/fts_diacriticsensitive.js
index 2396860e0db..4440e587ed7 100644
--- a/jstests/core/fts_diacriticsensitive.js
+++ b/jstests/core/fts_diacriticsensitive.js
@@ -14,7 +14,7 @@ coll.drop();
assert.commandWorked(coll.insert(
{_id: 0, a: "O próximo vôo à noite sobre o Atlântico, põe freqüentemente o único médico."}));
-assert.commandWorked(coll.createIndex({a: "text"}, {default_language: "portuguese"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {default_language: "portuguese"}));
assert.throws(function() {
queryIDS(coll, "hello", null, {$diacriticSensitive: "invalid"});
diff --git a/jstests/core/fts_explain.js b/jstests/core/fts_explain.js
index 9b87cedcc51..1f1f0a0e55b 100644
--- a/jstests/core/fts_explain.js
+++ b/jstests/core/fts_explain.js
@@ -14,7 +14,7 @@ const coll = db.fts_explain;
let res;
coll.drop();
-res = coll.createIndex({content: "text"}, {default_language: "none"});
+res = coll.ensureIndex({content: "text"}, {default_language: "none"});
assert.commandWorked(res);
res = coll.insert({content: "some data"});
diff --git a/jstests/core/fts_index.js b/jstests/core/fts_index.js
index 3080534c434..a41ea5a8dab 100644
--- a/jstests/core/fts_index.js
+++ b/jstests/core/fts_index.js
@@ -27,7 +27,7 @@ coll.getDB().createCollection(coll.getName());
//
// Spec passes text-specific index validation.
-assert.commandWorked(coll.createIndex({a: "text"}, {name: indexName, default_language: "spanish"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {name: indexName, default_language: "spanish"}));
assert.eq(1,
coll.getIndexes()
.filter(function(z) {
@@ -38,7 +38,7 @@ coll.dropIndexes();
// Spec fails text-specific index validation ("spanglish" unrecognized).
assert.commandFailed(
- coll.createIndex({a: "text"}, {name: indexName, default_language: "spanglish"}));
+ coll.ensureIndex({a: "text"}, {name: indexName, default_language: "spanglish"}));
assert.eq(0,
coll.getIndexes()
.filter(function(z) {
@@ -48,7 +48,7 @@ assert.eq(0,
coll.dropIndexes();
// Spec passes general index validation.
-assert.commandWorked(coll.createIndex({"$**": "text"}, {name: indexName}));
+assert.commandWorked(coll.ensureIndex({"$**": "text"}, {name: indexName}));
assert.eq(1,
coll.getIndexes()
.filter(function(z) {
@@ -58,7 +58,7 @@ assert.eq(1,
coll.dropIndexes();
// Spec fails general index validation ("a.$**" invalid field name for key).
-assert.commandFailed(coll.createIndex({"a.$**": "text"}, {name: indexName}));
+assert.commandFailed(coll.ensureIndex({"a.$**": "text"}, {name: indexName}));
assert.eq(0,
coll.getIndexes()
.filter(function(z) {
@@ -68,7 +68,7 @@ assert.eq(0,
coll.dropIndexes();
// SERVER-19519 Spec fails if '_fts' is specified on a non-text index.
-assert.commandFailed(coll.createIndex({_fts: 1}, {name: indexName}));
+assert.commandFailed(coll.ensureIndex({_fts: 1}, {name: indexName}));
assert.eq(0,
coll.getIndexes()
.filter(function(z) {
@@ -76,7 +76,7 @@ assert.eq(0,
})
.length);
coll.dropIndexes();
-assert.commandFailed(coll.createIndex({_fts: "text"}, {name: indexName}));
+assert.commandFailed(coll.ensureIndex({_fts: "text"}, {name: indexName}));
assert.eq(0,
coll.getIndexes()
.filter(function(z) {
@@ -92,22 +92,22 @@ coll.dropIndexes();
// Can create a text index on a collection where no documents have invalid language_override.
coll.insert({a: ""});
coll.insert({a: "", language: "spanish"});
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
coll.drop();
// Can't create a text index on a collection containing document with an invalid language_override.
coll.insert({a: "", language: "spanglish"});
-assert.commandFailed(coll.createIndex({a: "text"}));
+assert.commandFailed(coll.ensureIndex({a: "text"}));
coll.drop();
// Can insert documents with valid language_override into text-indexed collection.
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
coll.insert({a: ""});
assert.commandWorked(coll.insert({a: "", language: "spanish"}));
coll.drop();
// Can't insert documents with invalid language_override into text-indexed collection.
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
assert.writeError(coll.insert({a: "", language: "spanglish"}));
coll.drop();
@@ -115,69 +115,69 @@ coll.drop();
// 3. Collections may have at most one text index.
//
-// createIndex() becomes a no-op on an equivalent index spec.
+// ensureIndex() becomes a no-op on an equivalent index spec.
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
assert.eq(1, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}, {background: true}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {background: true}));
assert.eq(2, coll.getIndexes().length);
-assert.commandFailedWithCode(coll.createIndex({a: 1, b: 1, c: "text"}),
+assert.commandFailedWithCode(coll.ensureIndex({a: 1, b: 1, c: "text"}),
ErrorCodes.CannotCreateIndex);
assert.commandFailedWithCode(
- coll.createIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {b: 1}}),
+ coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {b: 1}}),
ErrorCodes.IndexOptionsConflict);
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}, {default_language: "english"}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {default_language: "english"}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}, {textIndexVersion: 2}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {textIndexVersion: 2}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}, {language_override: "language"}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {language_override: "language"}));
assert.eq(2, coll.getIndexes().length);
coll.drop();
// Two index specs are also considered equivalent if they differ only in 'textIndexVersion', and
-// createIndex() becomes a no-op on repeated requests that only differ in this way.
+// ensureIndex() becomes a no-op on repeated requests that only differ in this way.
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
assert.eq(1, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 1}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 1}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 2}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 2}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 3}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 3}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
assert.eq(2, coll.getIndexes().length);
coll.drop();
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
assert.eq(1, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 3}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 3}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 2}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 2}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 1}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 1}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
assert.eq(2, coll.getIndexes().length);
coll.drop();
-// createIndex() fails if a second text index would be built.
+// ensureIndex() fails if a second text index would be built.
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
assert.eq(1, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}));
-assert.eq(2, coll.getIndexes().length);
-assert.commandFailed(coll.createIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {d: 1}}));
-assert.commandFailed(coll.createIndex({a: 1, b: "text", c: 1}, {default_language: "none"}));
-assert.commandFailed(coll.createIndex({a: 1, b: "text", c: 1}, {language_override: "idioma"}));
-assert.commandFailed(coll.createIndex({a: 1, b: "text", c: 1}, {weights: {d: 1}}));
-assert.commandFailed(coll.createIndex({a: 1, b: "text", d: 1}));
-assert.commandFailed(coll.createIndex({a: 1, d: "text", c: 1}));
-assert.commandFailed(coll.createIndex({b: "text"}));
-assert.commandFailed(coll.createIndex({b: "text", c: 1}));
-assert.commandFailed(coll.createIndex({a: 1, b: "text"}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}));
+assert.eq(2, coll.getIndexes().length);
+assert.commandFailed(coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {d: 1}}));
+assert.commandFailed(coll.ensureIndex({a: 1, b: "text", c: 1}, {default_language: "none"}));
+assert.commandFailed(coll.ensureIndex({a: 1, b: "text", c: 1}, {language_override: "idioma"}));
+assert.commandFailed(coll.ensureIndex({a: 1, b: "text", c: 1}, {weights: {d: 1}}));
+assert.commandFailed(coll.ensureIndex({a: 1, b: "text", d: 1}));
+assert.commandFailed(coll.ensureIndex({a: 1, d: "text", c: 1}));
+assert.commandFailed(coll.ensureIndex({b: "text"}));
+assert.commandFailed(coll.ensureIndex({b: "text", c: 1}));
+assert.commandFailed(coll.ensureIndex({a: 1, b: "text"}));
coll.dropIndexes();
@@ -185,7 +185,7 @@ coll.dropIndexes();
// 4. Text indexes properly handle large keys.
//
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
var longstring = "";
var longstring2 = "";
@@ -201,7 +201,7 @@ coll.dropIndexes();
//
// 5. Bad weights test cases.
//
-assert.commandFailed(coll.createIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {}}));
-assert.commandFailed(coll.createIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}));
+assert.commandFailed(coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {}}));
+assert.commandFailed(coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}));
coll.drop();
diff --git a/jstests/core/fts_index2.js b/jstests/core/fts_index2.js
index 3ae6e45214e..1c8454002a7 100644
--- a/jstests/core/fts_index2.js
+++ b/jstests/core/fts_index2.js
@@ -14,7 +14,7 @@ coll1.drop();
coll2.drop();
assert.commandWorked(coll1.insert({a: {b: "some content"}}));
-assert.commandWorked(coll1.createIndex({"$**": "text"}));
+assert.commandWorked(coll1.ensureIndex({"$**": "text"}));
assert.eq(1, coll1.count({$text: {$search: "content"}}));
// Rename within same database.
diff --git a/jstests/core/fts_index3.js b/jstests/core/fts_index3.js
index 0f57c7a9d80..02bd9559591 100644
--- a/jstests/core/fts_index3.js
+++ b/jstests/core/fts_index3.js
@@ -12,7 +12,7 @@ var coll = db.fts_index3;
// 1) Create a text index on a single field, insert a document, update the value of the field, and
// verify that $text with the new value returns the document.
coll.drop();
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
assert.commandWorked(coll.insert({a: "hello"}));
assert.eq(1, coll.find({$text: {$search: "hello"}}).itcount());
assert.commandWorked(coll.update({}, {$set: {a: "world"}}));
@@ -21,7 +21,7 @@ assert.eq(1, coll.find({$text: {$search: "world"}}).itcount());
// 2) Same as #1, but with a wildcard text index.
coll.drop();
-assert.commandWorked(coll.createIndex({"$**": "text"}));
+assert.commandWorked(coll.ensureIndex({"$**": "text"}));
assert.commandWorked(coll.insert({a: "hello"}));
assert.eq(1, coll.find({$text: {$search: "hello"}}).itcount());
assert.commandWorked(coll.update({}, {$set: {a: "world"}}));
@@ -31,7 +31,7 @@ assert.eq(1, coll.find({$text: {$search: "world"}}).itcount());
// 3) Create a compound text index with an index prefix, insert a document, update the value of the
// index prefix field, and verify that $text with the new value returns the document.
coll.drop();
-assert.commandWorked(coll.createIndex({a: 1, b: "text"}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: "text"}));
assert.commandWorked(coll.insert({a: 1, b: "hello"}));
assert.eq(1, coll.find({a: 1, $text: {$search: "hello"}}).itcount());
assert.commandWorked(coll.update({}, {$set: {a: 2}}));
@@ -40,7 +40,7 @@ assert.eq(1, coll.find({a: 2, $text: {$search: "hello"}}).itcount());
// 4) Same as #3, but with a wildcard text index.
coll.drop();
-assert.commandWorked(coll.createIndex({a: 1, "$**": "text"}));
+assert.commandWorked(coll.ensureIndex({a: 1, "$**": "text"}));
assert.commandWorked(coll.insert({a: 1, b: "hello"}));
assert.eq(1, coll.find({a: 1, $text: {$search: "hello"}}).itcount());
assert.commandWorked(coll.update({}, {$set: {a: 2}}));
@@ -50,7 +50,7 @@ assert.eq(1, coll.find({a: 2, $text: {$search: "hello"}}).itcount());
// 5) Create a compound text index with an index suffix, insert a document, update the value of the
// index suffix field, and verify that $text with the new value returns the document.
coll.drop();
-assert.commandWorked(coll.createIndex({a: "text", b: 1}));
+assert.commandWorked(coll.ensureIndex({a: "text", b: 1}));
assert.commandWorked(coll.insert({a: "hello", b: 1}));
assert.eq(1, coll.find({b: 1, $text: {$search: "hello"}}).itcount());
assert.commandWorked(coll.update({}, {$set: {b: 2}}));
@@ -59,7 +59,7 @@ assert.eq(1, coll.find({b: 2, $text: {$search: "hello"}}).itcount());
// 6) Same as #5, but with a wildcard text index.
coll.drop();
-assert.commandWorked(coll.createIndex({"$**": "text", b: 1}));
+assert.commandWorked(coll.ensureIndex({"$**": "text", b: 1}));
assert.commandWorked(coll.insert({a: "hello", b: 1}));
assert.eq(1, coll.find({b: 1, $text: {$search: "hello"}}).itcount());
assert.commandWorked(coll.update({}, {$set: {b: 2}}));
@@ -69,7 +69,7 @@ assert.eq(1, coll.find({b: 2, $text: {$search: "hello"}}).itcount());
// 7) Create a text index on a single field, insert a document, update the language of the document
// (so as to change the stemming), and verify that $text with the new language returns the document.
coll.drop();
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
assert.commandWorked(coll.insert({a: "testing", language: "es"}));
assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount());
assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount());
@@ -79,7 +79,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()
// 8) Same as #7, but with a wildcard text index.
coll.drop();
-assert.commandWorked(coll.createIndex({"$**": "text"}));
+assert.commandWorked(coll.ensureIndex({"$**": "text"}));
assert.commandWorked(coll.insert({a: "testing", language: "es"}));
assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount());
assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount());
@@ -91,7 +91,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()
// subdocument (so as to change the stemming), and verify that $text with the new language returns
// the document.
coll.drop();
-assert.commandWorked(coll.createIndex({"a.b": "text"}));
+assert.commandWorked(coll.ensureIndex({"a.b": "text"}));
assert.commandWorked(coll.insert({a: {b: "testing", language: "es"}}));
assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount());
assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount());
@@ -101,7 +101,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()
// 10) Same as #9, but with a wildcard text index.
coll.drop();
-assert.commandWorked(coll.createIndex({"$**": "text"}));
+assert.commandWorked(coll.ensureIndex({"$**": "text"}));
assert.commandWorked(coll.insert({a: {b: "testing", language: "es"}}));
assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount());
assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount());
@@ -113,7 +113,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()
// update the language of the document (so as to change the stemming), and verify that $text with
// the new language returns the document.
coll.drop();
-assert.commandWorked(coll.createIndex({a: "text"}, {language_override: "idioma"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {language_override: "idioma"}));
assert.commandWorked(coll.insert({a: "testing", idioma: "es"}));
assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount());
assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount());
@@ -123,7 +123,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()
// 12) Same as #11, but with a wildcard text index.
coll.drop();
-assert.commandWorked(coll.createIndex({"$**": "text"}, {language_override: "idioma"}));
+assert.commandWorked(coll.ensureIndex({"$**": "text"}, {language_override: "idioma"}));
assert.commandWorked(coll.insert({a: "testing", idioma: "es"}));
assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount());
assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount());
diff --git a/jstests/core/fts_index_version1.js b/jstests/core/fts_index_version1.js
index 57b7c7710b6..8ae979c7dbe 100644
--- a/jstests/core/fts_index_version1.js
+++ b/jstests/core/fts_index_version1.js
@@ -3,19 +3,19 @@ var coll = db.fts_index_version1;
// Test basic English search.
coll.drop();
-assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 1}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 1}));
assert.commandWorked(coll.insert({a: "running"}));
assert.eq(1, coll.count({$text: {$search: "run"}}));
// Test search with a "language alias" only recognized in textIndexVersion:1 (note that the stopword
// machinery doesn't recognize these aliases).
coll.drop();
-assert.commandWorked(coll.createIndex({a: "text"}, {default_language: "eng", textIndexVersion: 1}));
+assert.commandWorked(coll.ensureIndex({a: "text"}, {default_language: "eng", textIndexVersion: 1}));
assert.commandWorked(coll.insert({a: "running"}));
assert.eq(1, coll.count({$text: {$search: "run"}}));
// Test that textIndexVersion:1 indexes ignore subdocument language annotations.
coll.drop();
-assert.commandWorked(coll.createIndex({"a.b": "text"}, {textIndexVersion: 1}));
+assert.commandWorked(coll.ensureIndex({"a.b": "text"}, {textIndexVersion: 1}));
assert.commandWorked(coll.insert({language: "none", a: {language: "english", b: "the"}}));
assert.eq(1, coll.count({$text: {$search: "the", $language: "none"}}));
diff --git a/jstests/core/fts_index_version2.js b/jstests/core/fts_index_version2.js
index 1e579ba12cb..10f803f30c6 100644
--- a/jstests/core/fts_index_version2.js
+++ b/jstests/core/fts_index_version2.js
@@ -15,7 +15,7 @@ assert.commandWorked(coll.insert(
{_id: 0, a: "O próximo Vôo à Noite sobre o Atlântico, Põe Freqüentemente o único Médico."}));
assert.commandWorked(
- coll.createIndex({a: "text"}, {default_language: "portuguese", textIndexVersion: 2}));
+ coll.ensureIndex({a: "text"}, {default_language: "portuguese", textIndexVersion: 2}));
assert.eq([0], queryIDS(coll, "próximo vôo à", null));
assert.eq([0], queryIDS(coll, "atlântico", null));
diff --git a/jstests/core/fts_mix.js b/jstests/core/fts_mix.js
index cdaaf1d17ff..abfdcc6aefd 100644
--- a/jstests/core/fts_mix.js
+++ b/jstests/core/fts_mix.js
@@ -77,7 +77,7 @@ tc.save({
// -------------------------------------------- INDEXING & WEIGHTING -------------------------------
// start with basic index, one item with default weight
-tc.createIndex({"title": "text"});
+tc.ensureIndex({"title": "text"});
// test the single result case..
res = tc.find({"$text": {"$search": "Victoria"}});
@@ -87,19 +87,19 @@ assert.eq(10, res[0]._id);
tc.dropIndexes();
// now let's see about multiple fields, with specific weighting
-tc.createIndex({"title": "text", "text": "text"}, {weights: {"title": 10}});
+tc.ensureIndex({"title": "text", "text": "text"}, {weights: {"title": 10}});
assert(resultsEq([9, 7, 8], queryIDS(tc, "members physics")));
tc.dropIndexes();
// test all-1 weighting with "$**"
-tc.createIndex({"$**": "text"});
+tc.ensureIndex({"$**": "text"});
assert(resultsEq([2, 8, 7], queryIDS(tc, "family tea estate")));
tc.dropIndexes();
// non-1 weight on "$**" + other weight specified for some field
-tc.createIndex({"$**": "text"}, {weights: {"$**": 10, "text": 2}});
+tc.ensureIndex({"$**": "text"}, {weights: {"$**": 10, "text": 2}});
assert(resultsEq([7, 5], queryIDS(tc, "Olympic Games gold medal")));
tc.dropIndexes();
@@ -108,7 +108,7 @@ tc.dropIndexes();
// ------------------------------------------
// go back to "$**": 1, "title": 10.. and test more specific "search" functionality!
-tc.createIndex({"$**": "text"}, {weights: {"title": 10}});
+tc.ensureIndex({"$**": "text"}, {weights: {"title": 10}});
// -------------------------------------------- STEMMING -------------------------------------------
diff --git a/jstests/core/fts_partition1.js b/jstests/core/fts_partition1.js
index efc148da675..055f574baf1 100644
--- a/jstests/core/fts_partition1.js
+++ b/jstests/core/fts_partition1.js
@@ -13,7 +13,7 @@ t.insert({_id: 2, x: 1, y: "bar"});
t.insert({_id: 3, x: 2, y: "foo"});
t.insert({_id: 4, x: 2, y: "bar"});
-t.createIndex({x: 1, y: "text"});
+t.ensureIndex({x: 1, y: "text"});
assert.throws(function() {
const cursor = t.find({"$text": {"$search": "foo"}});
diff --git a/jstests/core/fts_partition_no_multikey.js b/jstests/core/fts_partition_no_multikey.js
index b819c3abfbd..af28380a804 100644
--- a/jstests/core/fts_partition_no_multikey.js
+++ b/jstests/core/fts_partition_no_multikey.js
@@ -1,7 +1,7 @@
t = db.fts_partition_no_multikey;
t.drop();
-t.createIndex({x: 1, y: "text"});
+t.ensureIndex({x: 1, y: "text"});
assert.commandWorked(t.insert({x: 5, y: "this is fun"}));
diff --git a/jstests/core/fts_phrase.js b/jstests/core/fts_phrase.js
index dfe9d3692af..eae0a1c268d 100644
--- a/jstests/core/fts_phrase.js
+++ b/jstests/core/fts_phrase.js
@@ -11,7 +11,7 @@ t.save({_id: 1, title: "my blog post", text: "i am writing a blog. yay"});
t.save({_id: 2, title: "my 2nd post", text: "this is a new blog i am typing. yay"});
t.save({_id: 3, title: "knives are Fun", text: "this is a new blog i am writing. yay"});
-t.createIndex({"title": "text", text: "text"}, {weights: {title: 10}});
+t.ensureIndex({"title": "text", text: "text"}, {weights: {title: 10}});
res = t.find({"$text": {"$search": "blog write"}}, {score: {"$meta": "textScore"}}).sort({
score: {"$meta": "textScore"}
diff --git a/jstests/core/geo1.js b/jstests/core/geo1.js
index 8a80f59d692..7917799377e 100644
--- a/jstests/core/geo1.js
+++ b/jstests/core/geo1.js
@@ -19,10 +19,10 @@ assert.commandWorked(t.insert({zip: "94061", loc: [37.463911, 122.23396]}));
// test "2d" has to be first
assert.eq(1, t.getIndexKeys().length, "S1");
-t.createIndex({zip: 1, loc: "2d"});
+t.ensureIndex({zip: 1, loc: "2d"});
assert.eq(1, t.getIndexKeys().length, "S2");
-t.createIndex(idx);
+t.ensureIndex(idx);
assert.eq(2, t.getIndexKeys().length, "S3");
assert.eq(3, t.count(), "B1");
@@ -42,5 +42,5 @@ assert.eq("06525", t.find({loc: wb.loc})[0].zip, "C3");
t.drop();
-t.createIndex({loc: "2d"}, {min: -500, max: 500, bits: 4});
+t.ensureIndex({loc: "2d"}, {min: -500, max: 500, bits: 4});
assert.commandWorked(t.insert({loc: [200, 200]}));
diff --git a/jstests/core/geo10.js b/jstests/core/geo10.js
index b330ce52911..c33f90cdfbd 100644
--- a/jstests/core/geo10.js
+++ b/jstests/core/geo10.js
@@ -10,7 +10,7 @@
coll = db.geo10;
coll.drop();
-assert.commandWorked(db.geo10.createIndex({c: '2d', t: 1}, {min: 0, max: Math.pow(2, 40)}));
+assert.commandWorked(db.geo10.ensureIndex({c: '2d', t: 1}, {min: 0, max: Math.pow(2, 40)}));
assert.eq(2, db.geo10.getIndexes().length, "A3");
assert.commandWorked(db.geo10.insert({c: [1, 1], t: 1}));
diff --git a/jstests/core/geo2.js b/jstests/core/geo2.js
index b0552e2f773..01a4c467339 100644
--- a/jstests/core/geo2.js
+++ b/jstests/core/geo2.js
@@ -18,7 +18,7 @@ t.insert(arr);
assert.eq(t.count(), 100 * 100);
assert.eq(t.count(), n - 1);
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
function a(cur) {
var total = 0;
diff --git a/jstests/core/geo3.js b/jstests/core/geo3.js
index 40a3d9a5e75..e75c9b14245 100644
--- a/jstests/core/geo3.js
+++ b/jstests/core/geo3.js
@@ -19,7 +19,7 @@ t.insert(arr);
assert.eq(t.count(), 100 * 100);
assert.eq(t.count(), n - 1);
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
// Test the "query" parameter in $geoNear.
@@ -52,7 +52,7 @@ function testFiltering(msg) {
testFiltering("just loc");
assert.commandWorked(t.dropIndex({loc: "2d"}));
-assert.commandWorked(t.createIndex({loc: "2d", a: 1}));
+assert.commandWorked(t.ensureIndex({loc: "2d", a: 1}));
res = t.aggregate([
{$geoNear: {near: [50, 50], distanceField: "dist", query: {a: 2}}},
@@ -64,7 +64,7 @@ res.forEach(doc => assert.eq(2, doc.a, tojson(doc)));
testFiltering("loc and a");
assert.commandWorked(t.dropIndex({loc: "2d", a: 1}));
-assert.commandWorked(t.createIndex({loc: "2d", b: 1}));
+assert.commandWorked(t.ensureIndex({loc: "2d", b: 1}));
testFiltering("loc and b");
diff --git a/jstests/core/geo6.js b/jstests/core/geo6.js
index 0ee06508ea2..d6b43771b2c 100644
--- a/jstests/core/geo6.js
+++ b/jstests/core/geo6.js
@@ -6,7 +6,7 @@
t = db.geo6;
t.drop();
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
assert.eq(0, t.find().itcount(), "pre0");
assert.eq(0, t.find({loc: {$near: [50, 50]}}).itcount(), "pre1");
diff --git a/jstests/core/geo7.js b/jstests/core/geo7.js
index 9d1b7f574ca..4316c8d6c03 100644
--- a/jstests/core/geo7.js
+++ b/jstests/core/geo7.js
@@ -6,13 +6,13 @@ t.insert({_id: 2, y: [1, 1], z: 3});
t.insert({_id: 3, y: [1, 1], z: 4});
t.insert({_id: 4, y: [1, 1], z: 5});
-t.createIndex({y: "2d", z: 1});
+t.ensureIndex({y: "2d", z: 1});
assert.eq(1, t.find({y: [1, 1], z: 3}).itcount(), "A1");
t.dropIndex({y: "2d", z: 1});
-t.createIndex({y: "2d"});
+t.ensureIndex({y: "2d"});
assert.eq(1, t.find({y: [1, 1], z: 3}).itcount(), "A2");
t.insert({_id: 5, y: 5});
diff --git a/jstests/core/geo9.js b/jstests/core/geo9.js
index 4204c842987..eacd30f9a6d 100644
--- a/jstests/core/geo9.js
+++ b/jstests/core/geo9.js
@@ -14,8 +14,8 @@ t.save({_id: 4, a: [50, 50], b: [10, 10]});
t.save({_id: 5, a: [51, 51], b: [11, 11]});
t.save({_id: 6, a: [52, 52], b: [12, 12]});
-t.createIndex({a: "2d"});
-t.createIndex({b: "2d"});
+t.ensureIndex({a: "2d"});
+t.ensureIndex({b: "2d"});
function check(field) {
var q = {};
diff --git a/jstests/core/geo_2d_explain.js b/jstests/core/geo_2d_explain.js
index 109c5618795..370ef47e708 100644
--- a/jstests/core/geo_2d_explain.js
+++ b/jstests/core/geo_2d_explain.js
@@ -13,7 +13,7 @@ var n = 1000;
// insert n documents with integer _id, a can be 1-5, loc is close to [40, 40]
t.drop();
-t.createIndex({loc: "2d", _id: 1});
+t.ensureIndex({loc: "2d", _id: 1});
var x = 40;
var y = 40;
diff --git a/jstests/core/geo_2d_with_geojson_point.js b/jstests/core/geo_2d_with_geojson_point.js
index 3930f3c2c96..bb35fccd9da 100644
--- a/jstests/core/geo_2d_with_geojson_point.js
+++ b/jstests/core/geo_2d_with_geojson_point.js
@@ -4,7 +4,7 @@
var t = db.geo_2d_with_geojson_point;
t.drop();
-t.createIndex({loc: '2d'});
+t.ensureIndex({loc: '2d'});
var geoJSONPoint = {type: 'Point', coordinates: [0, 0]};
diff --git a/jstests/core/geo_allowedcomparisons.js b/jstests/core/geo_allowedcomparisons.js
index 01795941533..c1ef4efcba1 100644
--- a/jstests/core/geo_allowedcomparisons.js
+++ b/jstests/core/geo_allowedcomparisons.js
@@ -33,7 +33,7 @@ oldPolygon = [[-5, -5], [-5, 5], [5, 5], [5, -5], [-5, -5]];
oldCenter = [[0, 0], 1];
t.drop();
-t.createIndex({geo: "2d"});
+t.ensureIndex({geo: "2d"});
// 2d doesn't know what to do w/this
assert.writeError(t.insert({geo: geojsonPoint}));
// Old points are OK.
@@ -102,7 +102,7 @@ t.dropIndex({geo: "2d"});
runTests();
// 2dsphere index now.
-assert.commandWorked(t.createIndex({geo: "2dsphere"}));
+assert.commandWorked(t.ensureIndex({geo: "2dsphere"}));
// 2dsphere does not support arrays of points.
assert.writeError(t.insert({geo: [geojsonPoint2, geojsonPoint]}));
runTests();
diff --git a/jstests/core/geo_array0.js b/jstests/core/geo_array0.js
index 8a4e81283f8..0f27de02e49 100644
--- a/jstests/core/geo_array0.js
+++ b/jstests/core/geo_array0.js
@@ -16,7 +16,7 @@ function test(index) {
assert.commandWorked(res);
if (index) {
- assert.commandWorked(t.createIndex({loc: "2d", zip: 1}));
+ assert.commandWorked(t.ensureIndex({loc: "2d", zip: 1}));
assert.eq(2, t.getIndexKeys().length);
}
diff --git a/jstests/core/geo_array1.js b/jstests/core/geo_array1.js
index 6066ed1dc6f..08b6060f3cc 100644
--- a/jstests/core/geo_array1.js
+++ b/jstests/core/geo_array1.js
@@ -21,7 +21,7 @@ function test(index) {
}
if (index) {
- t.createIndex({loc: "2d"});
+ t.ensureIndex({loc: "2d"});
}
// Pull them back
diff --git a/jstests/core/geo_array2.js b/jstests/core/geo_array2.js
index 2a7a1303e0c..d2a197891e6 100644
--- a/jstests/core/geo_array2.js
+++ b/jstests/core/geo_array2.js
@@ -27,7 +27,7 @@ for (var i = -1; i < 2; i++) {
}
}
-assert.commandWorked(t.createIndex({loc: "2d", type: 1}));
+assert.commandWorked(t.ensureIndex({loc: "2d", type: 1}));
print("Starting testing phase... ");
diff --git a/jstests/core/geo_big_polygon.js b/jstests/core/geo_big_polygon.js
index db0d00cf6ff..eb2a24ad719 100644
--- a/jstests/core/geo_big_polygon.js
+++ b/jstests/core/geo_big_polygon.js
@@ -10,7 +10,7 @@
var coll = db.geo_big_polygon;
coll.drop();
-// coll.createIndex({ loc : "2dsphere" });
+// coll.ensureIndex({ loc : "2dsphere" });
var bigCRS = {type: "name", properties: {name: "urn:x-mongodb:crs:strictwinding:EPSG:4326"}};
@@ -56,7 +56,7 @@ assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20}}}).count(), 4)
assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20Comp}}}).count(), 1);
assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20Comp}}}).count(), 2);
-assert.commandWorked(coll.createIndex({loc: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({loc: "2dsphere"}));
assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20}}}).count(), 3);
assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20}}}).count(), 4);
@@ -81,11 +81,11 @@ assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20Comp}}}).count(), 1)
assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20Comp}}}).count(), 2);
// 2. Building index fails due to big polygon
-assert.commandFailed(coll.createIndex({loc: "2dsphere"}));
+assert.commandFailed(coll.ensureIndex({loc: "2dsphere"}));
// 3. After removing big polygon, index builds successfully
assert.commandWorked(coll.remove({_id: "bigPoly10"}));
-assert.commandWorked(coll.createIndex({loc: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({loc: "2dsphere"}));
// 4. With index, insert fails.
assert.writeError(coll.insert({_id: "bigPoly10", loc: bigPoly10}));
diff --git a/jstests/core/geo_big_polygon2.js b/jstests/core/geo_big_polygon2.js
index 53e0631e791..80339cb4fed 100644
--- a/jstests/core/geo_big_polygon2.js
+++ b/jstests/core/geo_big_polygon2.js
@@ -560,7 +560,7 @@ const nsidedPolys = [
];
// Populate with 2dsphere index
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}), "create 2dsphere index");
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}), "create 2dsphere index");
// Insert objects into collection
objects.forEach(function(o) {
@@ -573,10 +573,10 @@ objects.forEach(function(o) {
});
// Try creating other index types
-assert.commandWorked(coll.createIndex({geo: "2dsphere", a: 1}), "compound index, geo");
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere", a: 1}), "compound index, geo");
// These other index types will fail because of the GeoJSON documents
-assert.commandFailed(coll.createIndex({geo: "2dsphere", a: "text"}), "compound index, geo & text");
-assert.commandFailed(coll.createIndex({geo: "2d"}), "2d index");
+assert.commandFailed(coll.ensureIndex({geo: "2dsphere", a: "text"}), "compound index, geo & text");
+assert.commandFailed(coll.ensureIndex({geo: "2d"}), "2d index");
totalObjects = coll.count();
@@ -589,7 +589,7 @@ indexes.forEach(function(index) {
if (index != "none") {
// Create index
- assert.commandWorked(coll.createIndex({geo: index}), "create " + index + " index");
+ assert.commandWorked(coll.ensureIndex({geo: index}), "create " + index + " index");
}
// These polygons should not be queryable
diff --git a/jstests/core/geo_big_polygon3.js b/jstests/core/geo_big_polygon3.js
index cd4591dd66a..a55ce87c3d6 100644
--- a/jstests/core/geo_big_polygon3.js
+++ b/jstests/core/geo_big_polygon3.js
@@ -63,7 +63,7 @@ var bigPoly = {
};
// 2dsphere index required
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}), "2dsphere index");
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}), "2dsphere index");
// $nearSphere on big polygon should fail
assert.throws(function() {
@@ -222,7 +222,7 @@ assert.eq(totalDocs,
"crs84CRS or epsg4326CRS intersects");
// Add index and look again for stored point & spherical CRS documents
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}), "2dsphere index");
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}), "2dsphere index");
assert.eq(totalDocs,
coll.count({geo: {$geoWithin: {$geometry: poly}}}),
diff --git a/jstests/core/geo_borders.js b/jstests/core/geo_borders.js
index 01989a445bc..8eac710db0f 100644
--- a/jstests/core/geo_borders.js
+++ b/jstests/core/geo_borders.js
@@ -24,11 +24,11 @@ overallMax = 1;
// Create a point index slightly smaller than the points we have
var res =
- t.createIndex({loc: "2d"}, {max: overallMax - epsilon / 2, min: overallMin + epsilon / 2});
+ t.ensureIndex({loc: "2d"}, {max: overallMax - epsilon / 2, min: overallMin + epsilon / 2});
assert.commandFailed(res);
// Create a point index only slightly bigger than the points we have
-res = t.createIndex({loc: "2d"}, {max: overallMax + epsilon, min: overallMin - epsilon});
+res = t.ensureIndex({loc: "2d"}, {max: overallMax + epsilon, min: overallMin - epsilon});
assert.commandWorked(res);
// ************
diff --git a/jstests/core/geo_box1.js b/jstests/core/geo_box1.js
index 28fe85c83cf..300e65c2dc6 100644
--- a/jstests/core/geo_box1.js
+++ b/jstests/core/geo_box1.js
@@ -14,7 +14,7 @@ for (x = 0; x <= 20; x++) {
}
}
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
searches = [
[[1, 2], [4, 5]],
diff --git a/jstests/core/geo_box2.js b/jstests/core/geo_box2.js
index e4e51ec9e10..f0f99b15ea0 100644
--- a/jstests/core/geo_box2.js
+++ b/jstests/core/geo_box2.js
@@ -14,10 +14,10 @@ for (i = 1; i < 10; i++) {
}
}
-t.createIndex({"loc": "2d"});
+t.ensureIndex({"loc": "2d"});
assert.eq(9, t.find({loc: {$within: {$box: [[4, 4], [6, 6]]}}}).itcount(), "A1");
t.dropIndex({"loc": "2d"});
-t.createIndex({"loc": "2d"}, {"min": 0, "max": 10});
+t.ensureIndex({"loc": "2d"}, {"min": 0, "max": 10});
assert.eq(9, t.find({loc: {$within: {$box: [[4, 4], [6, 6]]}}}).itcount(), "B1");
diff --git a/jstests/core/geo_box3.js b/jstests/core/geo_box3.js
index 4a91ffb0d1d..7f9dd12ea60 100644
--- a/jstests/core/geo_box3.js
+++ b/jstests/core/geo_box3.js
@@ -7,7 +7,7 @@
t = db.geo_box3;
t.drop();
t.insert({point: {x: -15000000, y: 10000000}});
-t.createIndex({point: "2d"}, {min: -21000000, max: 21000000});
+t.ensureIndex({point: "2d"}, {min: -21000000, max: 21000000});
var c = t.find({point: {"$within": {"$box": [[-20000000, 7000000], [0, 15000000]]}}});
assert.eq(1, c.count(), "A1");
@@ -15,7 +15,7 @@ assert.eq(1, c.count(), "A1");
t = db.geo_box3;
t.drop();
t.insert({point: {x: -15, y: 10}});
-t.createIndex({point: "2d"}, {min: -21, max: 21});
+t.ensureIndex({point: "2d"}, {min: -21, max: 21});
var c = t.find({point: {"$within": {"$box": [[-20, 7], [0, 15]]}}});
assert.eq(1, c.count(), "B1");
@@ -24,13 +24,13 @@ assert.eq(1, c.count(), "B1");
t = db.geo_box3;
t.drop();
t.insert({point: {x: 1.0, y: 1.0}});
-t.createIndex({point: "2d"}, {min: -2, max: 2});
+t.ensureIndex({point: "2d"}, {min: -2, max: 2});
var c = t.find({point: {"$within": {"$box": [[.1, .1], [1.99, 1.99]]}}});
assert.eq(1, c.count(), "C1");
t = db.geo_box3;
t.drop();
t.insert({point: {x: 3.9, y: 3.9}});
-t.createIndex({point: "2d"}, {min: 0, max: 4});
+t.ensureIndex({point: "2d"}, {min: 0, max: 4});
var c = t.find({point: {"$within": {"$box": [[2.05, 2.05], [3.99, 3.99]]}}});
assert.eq(1, c.count(), "D1");
diff --git a/jstests/core/geo_center_sphere1.js b/jstests/core/geo_center_sphere1.js
index cbef0b4302d..df3ea9bb36c 100644
--- a/jstests/core/geo_center_sphere1.js
+++ b/jstests/core/geo_center_sphere1.js
@@ -45,7 +45,7 @@ function test(index) {
assert.commandWorked(bulk.execute());
if (index) {
- t.createIndex({loc: index});
+ t.ensureIndex({loc: index});
}
for (i = 0; i < searches.length; i++) {
diff --git a/jstests/core/geo_center_sphere2.js b/jstests/core/geo_center_sphere2.js
index 2b5e8be5cab..4a263cba259 100644
--- a/jstests/core/geo_center_sphere2.js
+++ b/jstests/core/geo_center_sphere2.js
@@ -50,7 +50,7 @@ for (var test = 0; test < numTests; test++) {
do {
t.drop();
startPoint = randomPoint();
- t.createIndex({loc: "2d"}, {bits: bits});
+ t.ensureIndex({loc: "2d"}, {bits: bits});
} while (!pointIsOK(startPoint, radius));
var pointsIn = 0;
diff --git a/jstests/core/geo_circle1.js b/jstests/core/geo_circle1.js
index 0df085bcb4d..65d2a467eab 100644
--- a/jstests/core/geo_circle1.js
+++ b/jstests/core/geo_circle1.js
@@ -29,7 +29,7 @@ for (x = 0; x <= 20; x++) {
}
}
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
for (i = 0; i < searches.length; i++) {
// print( tojson( searches[i] ) + "\t" + correct[i].length )
diff --git a/jstests/core/geo_circle2.js b/jstests/core/geo_circle2.js
index 6be02377259..30a826b4f27 100644
--- a/jstests/core/geo_circle2.js
+++ b/jstests/core/geo_circle2.js
@@ -7,7 +7,7 @@
t = db.geo_circle2;
t.drop();
-t.createIndex({loc: "2d", categories: 1}, {"name": "placesIdx", "min": -100, "max": 100});
+t.ensureIndex({loc: "2d", categories: 1}, {"name": "placesIdx", "min": -100, "max": 100});
t.insert(
{"uid": 368900, "loc": {"x": -36, "y": -8}, "categories": ["sports", "hotel", "restaurant"]});
diff --git a/jstests/core/geo_circle2a.js b/jstests/core/geo_circle2a.js
index f647bdc82ea..b084d1027ec 100644
--- a/jstests/core/geo_circle2a.js
+++ b/jstests/core/geo_circle2a.js
@@ -6,7 +6,7 @@
var coll = db.geo_circle2a;
coll.drop();
coll.insert({p: [1112, 3473], t: [{k: 'a', v: 'b'}, {k: 'c', v: 'd'}]});
-coll.createIndex({p: '2d', 't.k': 1}, {min: 0, max: 10000});
+coll.ensureIndex({p: '2d', 't.k': 1}, {min: 0, max: 10000});
// Succeeds, since on direct lookup should not use the index
assert(1 == coll.find({p: [1112, 3473], 't.k': 'a'}).count(), "A");
@@ -18,7 +18,7 @@ coll.drop();
coll.insert({point: [1, 10], tags: [{k: 'key', v: 'value'}, {k: 'key2', v: 123}]});
coll.insert({point: [1, 10], tags: [{k: 'key', v: 'value'}]});
-coll.createIndex({point: "2d", "tags.k": 1, "tags.v": 1});
+coll.ensureIndex({point: "2d", "tags.k": 1, "tags.v": 1});
// Succeeds, since should now lookup multi-keys correctly
assert(2 == coll.find({point: {$within: {$box: [[0, 0], [12, 12]]}}}).count(), "C");
@@ -31,7 +31,7 @@ coll.drop();
coll.insert({point: [1, 10], tags: [{k: {'hello': 'world'}, v: 'value'}, {k: 'key2', v: 123}]});
coll.insert({point: [1, 10], tags: [{k: 'key', v: 'value'}]});
-coll.createIndex({point: "2d", "tags.k": 1, "tags.v": 1});
+coll.ensureIndex({point: "2d", "tags.k": 1, "tags.v": 1});
// Succeeds, should be able to look up the complex element
assert(1 ==
diff --git a/jstests/core/geo_circle3.js b/jstests/core/geo_circle3.js
index e931e96783d..3be564cd180 100644
--- a/jstests/core/geo_circle3.js
+++ b/jstests/core/geo_circle3.js
@@ -14,7 +14,7 @@ db.places.save({"_id": n++, "loc": {"x": 4.9999, "y": 52.0001}});
db.places.save({"_id": n++, "loc": {"x": 5.0001, "y": 52.0001}});
db.places.save({"_id": n++, "loc": {"x": 4.9999, "y": 51.9999}});
db.places.save({"_id": n++, "loc": {"x": 5.0001, "y": 51.9999}});
-db.places.createIndex({loc: "2d"});
+db.places.ensureIndex({loc: "2d"});
radius = 0.0001;
center = [5, 52];
// print(db.places.find({"loc" : {"$within" : {"$center" : [center, radius]}}}).count())
diff --git a/jstests/core/geo_circle4.js b/jstests/core/geo_circle4.js
index 04ce685db38..1feb72a2e48 100644
--- a/jstests/core/geo_circle4.js
+++ b/jstests/core/geo_circle4.js
@@ -18,7 +18,7 @@ function test(index) {
db.server848.save({"_id": 8, "loc": {"x": 4.9999, "y": 51.9999}});
db.server848.save({"_id": 9, "loc": {"x": 5.0001, "y": 51.9999}});
if (index) {
- db.server848.createIndex({loc: "2d"});
+ db.server848.ensureIndex({loc: "2d"});
}
r = db.server848.find({"loc": {"$within": {"$center": [center, radius]}}}, {_id: 1});
assert.eq(5, r.count(), "A1");
diff --git a/jstests/core/geo_circle5.js b/jstests/core/geo_circle5.js
index 27b973a8ede..34b3773ad00 100644
--- a/jstests/core/geo_circle5.js
+++ b/jstests/core/geo_circle5.js
@@ -8,7 +8,7 @@ db.server1238.drop();
db.server1238.remove({});
db.server1238.save({loc: [5000000, 900000], id: 1});
db.server1238.save({loc: [5000000, 900000], id: 2});
-db.server1238.createIndex({loc: "2d"}, {min: -21000000, max: 21000000});
+db.server1238.ensureIndex({loc: "2d"}, {min: -21000000, max: 21000000});
db.server1238.save({loc: [5000000, 900000], id: 3});
db.server1238.save({loc: [5000000, 900000], id: 4});
diff --git a/jstests/core/geo_exactfetch.js b/jstests/core/geo_exactfetch.js
index 93b0b7afcda..68ecc9941ae 100644
--- a/jstests/core/geo_exactfetch.js
+++ b/jstests/core/geo_exactfetch.js
@@ -7,7 +7,7 @@ t.drop();
function test(indexname) {
assert.eq(1, t.find({lon_lat: [-71.34895, 42.46037]}).itcount(), indexname);
- t.createIndex({lon_lat: indexname, population: -1});
+ t.ensureIndex({lon_lat: indexname, population: -1});
assert.eq(2, t.find({lon_lat: {$nearSphere: [-71.34895, 42.46037]}}).itcount(), indexname);
assert.eq(1, t.find({lon_lat: [-71.34895, 42.46037]}).itcount(), indexname);
t.dropIndex({lon_lat: indexname, population: -1});
diff --git a/jstests/core/geo_fiddly_box.js b/jstests/core/geo_fiddly_box.js
index 9f5a9e8d6c4..6c2adbe66c6 100644
--- a/jstests/core/geo_fiddly_box.js
+++ b/jstests/core/geo_fiddly_box.js
@@ -11,7 +11,7 @@
t = db.geo_fiddly_box;
t.drop();
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
t.insert({"loc": [3, 1]});
t.insert({"loc": [3, 0.5]});
@@ -35,7 +35,7 @@ step = 1;
numItems = 0;
t.drop();
-t.createIndex({loc: "2d"}, {max: max + epsilon / 2, min: min - epsilon / 2});
+t.ensureIndex({loc: "2d"}, {max: max + epsilon / 2, min: min - epsilon / 2});
for (var x = min; x <= max; x += step) {
for (var y = min; y <= max; y += step) {
diff --git a/jstests/core/geo_fiddly_box2.js b/jstests/core/geo_fiddly_box2.js
index a0f87203163..6a40b5032b5 100644
--- a/jstests/core/geo_fiddly_box2.js
+++ b/jstests/core/geo_fiddly_box2.js
@@ -16,18 +16,18 @@ t.insert({"letter": "B", "position": [2, 0]});
t.insert({"letter": "L", "position": [3, 0]});
t.insert({"letter": "E", "position": [4, 0]});
-t.createIndex({position: "2d"});
+t.ensureIndex({position: "2d"});
result = t.find({"position": {"$within": {"$box": [[-3, -1], [0, 1]]}}});
assert.eq(4, result.count());
t.dropIndex({position: "2d"});
-t.createIndex({position: "2d"}, {min: -10000000, max: 10000000});
+t.ensureIndex({position: "2d"}, {min: -10000000, max: 10000000});
result = t.find({"position": {"$within": {"$box": [[-3, -1], [0, 1]]}}});
assert.eq(4, result.count());
t.dropIndex({position: "2d"});
-t.createIndex({position: "2d"}, {min: -1000000000, max: 1000000000});
+t.ensureIndex({position: "2d"}, {min: -1000000000, max: 1000000000});
result = t.find({"position": {"$within": {"$box": [[-3, -1], [0, 1]]}}});
assert.eq(4, result.count());
diff --git a/jstests/core/geo_invalid_2d_params.js b/jstests/core/geo_invalid_2d_params.js
index 33419302b47..b538d430a66 100644
--- a/jstests/core/geo_invalid_2d_params.js
+++ b/jstests/core/geo_invalid_2d_params.js
@@ -1,8 +1,8 @@
var t = db.geo_invalid_2d_params;
t.drop();
-assert.commandFailed(t.createIndex({loc: "2d"}, {bits: 33}));
-assert.commandFailed(t.createIndex({loc: "2d"}, {min: -1, max: -1}));
-assert.commandFailed(t.createIndex({loc: "2d"}, {bits: -1}));
-assert.commandFailed(t.createIndex({loc: "2d"}, {min: 10, max: 9}));
-assert.commandWorked(t.createIndex({loc: "2d"}, {bits: 1, min: -1, max: 1}));
+assert.commandFailed(t.ensureIndex({loc: "2d"}, {bits: 33}));
+assert.commandFailed(t.ensureIndex({loc: "2d"}, {min: -1, max: -1}));
+assert.commandFailed(t.ensureIndex({loc: "2d"}, {bits: -1}));
+assert.commandFailed(t.ensureIndex({loc: "2d"}, {min: 10, max: 9}));
+assert.commandWorked(t.ensureIndex({loc: "2d"}, {bits: 1, min: -1, max: 1}));
diff --git a/jstests/core/geo_mindistance.js b/jstests/core/geo_mindistance.js
index 8994892c77d..33153e62008 100644
--- a/jstests/core/geo_mindistance.js
+++ b/jstests/core/geo_mindistance.js
@@ -56,7 +56,7 @@ for (var x = 0; x <= 10; x += 1) {
}
}
-t.createIndex({loc: "2dsphere"});
+t.ensureIndex({loc: "2dsphere"});
var n_docs = t.count(), geoJSONPoint = {type: 'Point', coordinates: [0, 0]}, legacyPoint = [0, 0];
diff --git a/jstests/core/geo_mindistance_boundaries.js b/jstests/core/geo_mindistance_boundaries.js
index 7024cfa2ec9..9d556b341ac 100644
--- a/jstests/core/geo_mindistance_boundaries.js
+++ b/jstests/core/geo_mindistance_boundaries.js
@@ -9,7 +9,7 @@ t.drop();
t.insert({loc: [1, 0]}); // 1 degree of longitude from origin.
/* $minDistance is supported for 2dsphere index only, not 2d */
-t.createIndex({loc: "2dsphere"});
+t.ensureIndex({loc: "2dsphere"});
//
// Useful constants.
diff --git a/jstests/core/geo_multikey0.js b/jstests/core/geo_multikey0.js
index 27075a779ee..827dd9a41a1 100644
--- a/jstests/core/geo_multikey0.js
+++ b/jstests/core/geo_multikey0.js
@@ -11,7 +11,7 @@ assert.eq(
// Check that conflicting constraints are satisfied by parallel array elements with a 2d index on
// loc.
if (0) { // SERVER-3793
- t.createIndex({loc: '2d'});
+ t.ensureIndex({loc: '2d'});
assert.eq(
1,
t.count({loc: {x: 20, y: 30}, $and: [{loc: {$gt: {x: 20, y: 35}, $lt: {x: 20, y: 34}}}]}));
@@ -26,6 +26,6 @@ assert.eq(1, t.count({loc: [20, 30], x: {$gt: 1.7, $lt: 1.2}}));
// Check that conflicting constraints are satisfied by parallel array elements of x with a 2d index
// on loc,x.
if (0) { // SERVER-3793
- t.createIndex({loc: '2d', x: 1});
+ t.ensureIndex({loc: '2d', x: 1});
assert.eq(1, t.count({loc: [20, 30], x: {$gt: 1.7, $lt: 1.2}}));
}
diff --git a/jstests/core/geo_multikey1.js b/jstests/core/geo_multikey1.js
index e6d0ec086da..9c092f4ec31 100644
--- a/jstests/core/geo_multikey1.js
+++ b/jstests/core/geo_multikey1.js
@@ -12,7 +12,7 @@ for (i = 0; i < 10; ++i) {
t.save({loc: locArr, a: arr, b: arr, c: arr});
// Parallel arrays are allowed for geo indexes.
-assert.commandWorked(t.createIndex({loc: '2d', a: 1, b: 1, c: 1}));
+assert.commandWorked(t.ensureIndex({loc: '2d', a: 1, b: 1, c: 1}));
// Parallel arrays are not allowed for normal indexes.
-assert.commandFailed(t.createIndex({loc: 1, a: 1, b: 1, c: 1}));
+assert.commandFailed(t.ensureIndex({loc: 1, a: 1, b: 1, c: 1}));
diff --git a/jstests/core/geo_multinest0.js b/jstests/core/geo_multinest0.js
index b76c18dbd5c..6c0106d70df 100644
--- a/jstests/core/geo_multinest0.js
+++ b/jstests/core/geo_multinest0.js
@@ -16,7 +16,7 @@ var res =
t.insert({zip: "10003", data: [{loc: [30, 30], type: "home"}, {loc: [50, 50], type: "work"}]});
assert.commandWorked(res);
-assert.commandWorked(t.createIndex({"data.loc": "2d", zip: 1}));
+assert.commandWorked(t.ensureIndex({"data.loc": "2d", zip: 1}));
assert.eq(2, t.getIndexKeys().length);
res =
@@ -41,7 +41,7 @@ t.insert({zip: "10002", data: [{loc: [20, 20], type: "home"}, {loc: [50, 50], ty
res = t.insert({zip: "10003", data: [{loc: [{x: 30, y: 30}, [50, 50]], type: "home"}]});
assert(!res.hasWriteError());
-assert.commandWorked(t.createIndex({"data.loc": "2d", zip: 1}));
+assert.commandWorked(t.ensureIndex({"data.loc": "2d", zip: 1}));
assert.eq(2, t.getIndexKeys().length);
res =
diff --git a/jstests/core/geo_multinest1.js b/jstests/core/geo_multinest1.js
index a3fb424829e..d033cfa86b8 100644
--- a/jstests/core/geo_multinest1.js
+++ b/jstests/core/geo_multinest1.js
@@ -16,7 +16,7 @@ var res =
t.insert({zip: "10003", data: [{loc: [30, 30], type: "home"}, {loc: [49, 49], type: "work"}]});
assert.commandWorked(res);
-assert.commandWorked(t.createIndex({"data.loc": "2d", zip: 1}));
+assert.commandWorked(t.ensureIndex({"data.loc": "2d", zip: 1}));
assert.eq(2, t.getIndexKeys().length);
res =
diff --git a/jstests/core/geo_near_bounds_overflow.js b/jstests/core/geo_near_bounds_overflow.js
index 1d13d568220..ff674e89052 100644
--- a/jstests/core/geo_near_bounds_overflow.js
+++ b/jstests/core/geo_near_bounds_overflow.js
@@ -13,7 +13,7 @@ function testBounds(min, max) {
// Handle case where either 1. indexLambda will fail but not throw. We are asserting it
// works, so the outer lambda generates an exception. 2. indexLambda itself will throw.
const indexLambda = function(t) {
- return t.createIndex({loc: '2d'}, indexBounds);
+ return t.ensureIndex({loc: '2d'}, indexBounds);
};
const assertLambda = function(t, lambda) {
assert.commandWorked(lambda(t));
diff --git a/jstests/core/geo_near_random1.js b/jstests/core/geo_near_random1.js
index 52dc1e34cbb..b6350e6c6a7 100644
--- a/jstests/core/geo_near_random1.js
+++ b/jstests/core/geo_near_random1.js
@@ -34,7 +34,7 @@ test.testPt(test.mkPt(), opts);
// Test $nearSphere with a 2dsphere index
assert.commandWorked(db.geo_near_random1.dropIndex({loc: '2d'}));
-assert.commandWorked(db.geo_near_random1.createIndex({loc: '2dsphere'}));
+assert.commandWorked(db.geo_near_random1.ensureIndex({loc: '2dsphere'}));
test.testPt([0, 0], opts);
test.testPt(test.mkPt(), opts);
test.testPt(test.mkPt(), opts);
diff --git a/jstests/core/geo_near_random2.js b/jstests/core/geo_near_random2.js
index 4ffa95cffae..c524e7a7da4 100644
--- a/jstests/core/geo_near_random2.js
+++ b/jstests/core/geo_near_random2.js
@@ -38,7 +38,7 @@ test.testPt(test.mkPt(0.8), opts);
// Test $nearSphere with 2dsphere index
assert.commandWorked(db.geo_near_random2.dropIndex({loc: '2d'}));
-assert.commandWorked(db.geo_near_random2.createIndex({loc: '2dsphere'}));
+assert.commandWorked(db.geo_near_random2.ensureIndex({loc: '2dsphere'}));
test.testPt([0, 0], opts);
test.testPt(test.mkPt(0.8), opts);
test.testPt(test.mkPt(0.8), opts);
diff --git a/jstests/core/geo_nearwithin.js b/jstests/core/geo_nearwithin.js
index 6ded21dbd83..37d963b3ddc 100644
--- a/jstests/core/geo_nearwithin.js
+++ b/jstests/core/geo_nearwithin.js
@@ -13,7 +13,7 @@ for (var x = -points; x < points; x += 1) {
}
}
-assert.commandWorked(t.createIndex({geo: "2d"}));
+assert.commandWorked(t.ensureIndex({geo: "2d"}));
const runQuery = (center) =>
t.find({$and: [{geo: {$near: [0, 0]}}, {geo: {$within: {$center: center}}}]}).toArray();
diff --git a/jstests/core/geo_oob_sphere.js b/jstests/core/geo_oob_sphere.js
index 08a10758c77..3a878f06b78 100644
--- a/jstests/core/geo_oob_sphere.js
+++ b/jstests/core/geo_oob_sphere.js
@@ -15,7 +15,7 @@ assert.commandWorked(coll.insert({loc: {x: 30, y: 89}}));
assert.commandWorked(coll.insert({loc: {x: 30, y: 89}}));
assert.commandWorked(coll.insert({loc: {x: 30, y: 91}}));
-assert.commandWorked(coll.createIndex({loc: "2d"}));
+assert.commandWorked(coll.ensureIndex({loc: "2d"}));
assert.throws(function() {
coll.find({loc: {$nearSphere: [30, 91], $maxDistance: 0.25}}).count();
diff --git a/jstests/core/geo_operator_crs.js b/jstests/core/geo_operator_crs.js
index 6118c4efcc7..cab73fedb0f 100644
--- a/jstests/core/geo_operator_crs.js
+++ b/jstests/core/geo_operator_crs.js
@@ -14,7 +14,7 @@ coll.drop();
// Test 2dsphere index
//
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}));
var legacyZeroPt = [0, 0];
var jsonZeroPt = {type: "Point", coordinates: [0, 0]};
@@ -42,7 +42,7 @@ assert.commandWorked(coll.dropIndexes());
// Test 2d Index
//
-assert.commandWorked(coll.createIndex({geo: "2d"}));
+assert.commandWorked(coll.ensureIndex({geo: "2d"}));
assert.commandWorked(coll.insert({geo: legacy90Pt}));
@@ -55,7 +55,7 @@ assert.close(result[0].dis, Math.PI / 2);
// Test with a 2d and 2dsphere index using the aggregation $geoNear stage.
//
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}));
result = coll.aggregate({$geoNear: {near: jsonZeroPt, distanceField: "dis"}}).toArray();
assert.close(result[0].dis, (Math.PI / 2) * earthRadiusMeters);
}());
diff --git a/jstests/core/geo_or.js b/jstests/core/geo_or.js
index d571e3ad6e3..04caca0e106 100644
--- a/jstests/core/geo_or.js
+++ b/jstests/core/geo_or.js
@@ -15,7 +15,7 @@ t.save({loc: q});
var indexname = "2dsphere";
-t.createIndex({loc: indexname});
+t.ensureIndex({loc: indexname});
assert.eq(1, t.find({loc: p}).itcount(), indexname);
@@ -87,7 +87,7 @@ t.dropIndexes();
var indexname = "2d";
-t.createIndex({loc: indexname});
+t.ensureIndex({loc: indexname});
assert.eq(2,
t.find({
diff --git a/jstests/core/geo_poly_edge.js b/jstests/core/geo_poly_edge.js
index eee43bfc55c..971483e9eef 100644
--- a/jstests/core/geo_poly_edge.js
+++ b/jstests/core/geo_poly_edge.js
@@ -8,7 +8,7 @@
var coll = db.getCollection('jstests_geo_poly_edge');
coll.drop();
-coll.createIndex({loc: "2d"});
+coll.ensureIndex({loc: "2d"});
coll.insert({loc: [10, 10]});
coll.insert({loc: [10, -10]});
diff --git a/jstests/core/geo_poly_line.js b/jstests/core/geo_poly_line.js
index 49e394d140e..3eff8d12496 100644
--- a/jstests/core/geo_poly_line.js
+++ b/jstests/core/geo_poly_line.js
@@ -12,7 +12,7 @@ t.insert({loc: [2, 0]});
t.insert({loc: [3, 0]});
t.insert({loc: [4, 0]});
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
printjson(t.find({loc: {"$within": {"$polygon": [[0, 0], [2, 0], [4, 0]]}}}).toArray());
diff --git a/jstests/core/geo_polygon1.js b/jstests/core/geo_polygon1.js
index 3d6d2ad81b2..34b0cafa1d4 100644
--- a/jstests/core/geo_polygon1.js
+++ b/jstests/core/geo_polygon1.js
@@ -13,7 +13,7 @@ for (x = 1; x < 9; x++) {
}
}
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
triangle = [[0, 0], [1, 1], [0, 2]];
@@ -50,7 +50,7 @@ pacman = [
];
t.save({loc: [1, 3]}); // Add a point that's in
-assert.commandWorked(t.createIndex({loc: "2d"}));
+assert.commandWorked(t.ensureIndex({loc: "2d"}));
assert.eq(1, t.find({loc: {$within: {$polygon: pacman}}}).count(), "Pacman single point");
diff --git a/jstests/core/geo_polygon2.js b/jstests/core/geo_polygon2.js
index 7a6ad0aedb5..e5dc6d4e941 100644
--- a/jstests/core/geo_polygon2.js
+++ b/jstests/core/geo_polygon2.js
@@ -231,7 +231,7 @@ for (var test = 0; test < numTests; test++) {
}
}
- var res = t.createIndex({loc: "2d"}, {bits: 1 + bits, max: bounds[1], min: bounds[0]});
+ var res = t.ensureIndex({loc: "2d"}, {bits: 1 + bits, max: bounds[1], min: bounds[0]});
assert.commandWorked(res);
t.insert({loc: allPointsIn});
diff --git a/jstests/core/geo_queryoptimizer.js b/jstests/core/geo_queryoptimizer.js
index 17b3c5997f2..56653551ba7 100644
--- a/jstests/core/geo_queryoptimizer.js
+++ b/jstests/core/geo_queryoptimizer.js
@@ -6,7 +6,7 @@
t = db.geo_qo1;
t.drop();
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
t.insert({'issue': 0});
t.insert({'issue': 1});
diff --git a/jstests/core/geo_regex0.js b/jstests/core/geo_regex0.js
index 7629c193ea2..1add7f4e0c3 100644
--- a/jstests/core/geo_regex0.js
+++ b/jstests/core/geo_regex0.js
@@ -4,7 +4,7 @@
t = db.regex0;
t.drop();
-t.createIndex({point: '2d', words: 1});
+t.ensureIndex({point: '2d', words: 1});
t.insert({point: [1, 1], words: ['foo', 'bar']});
regex = {
diff --git a/jstests/core/geo_s2cursorlimitskip.js b/jstests/core/geo_s2cursorlimitskip.js
index 3413314fd27..f599ccd5b62 100644
--- a/jstests/core/geo_s2cursorlimitskip.js
+++ b/jstests/core/geo_s2cursorlimitskip.js
@@ -15,7 +15,7 @@
var testDB = db.getSiblingDB("geo_s2cursorlimitskip");
var t = testDB.geo_s2getmmm;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
Random.setRandomSeed();
var random = Random.rand;
diff --git a/jstests/core/geo_s2dedupnear.js b/jstests/core/geo_s2dedupnear.js
index 0619d307bfa..bbf92ded8d7 100644
--- a/jstests/core/geo_s2dedupnear.js
+++ b/jstests/core/geo_s2dedupnear.js
@@ -6,7 +6,7 @@
t = db.geo_s2dedupnear;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
var x = {
"type": "Polygon",
"coordinates": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]
diff --git a/jstests/core/geo_s2descindex.js b/jstests/core/geo_s2descindex.js
index c4ebb435a55..4a945895c57 100644
--- a/jstests/core/geo_s2descindex.js
+++ b/jstests/core/geo_s2descindex.js
@@ -34,7 +34,7 @@ for (var t = 0; t < descriptors.length; t++) {
jsTest.log("Trying 2dsphere index with descriptor " + tojson(descriptor));
coll.drop();
- coll.createIndex(descriptor);
+ coll.ensureIndex(descriptor);
coll.insert(docA);
coll.insert(docB);
@@ -55,7 +55,7 @@ for (var t = 0; t < descriptors.length; t++) {
jsTest.log("Trying case found in wild...");
coll.drop();
-coll.createIndex({coordinates: "2dsphere", field: -1});
+coll.ensureIndex({coordinates: "2dsphere", field: -1});
coll.insert({coordinates: [-118.240013, 34.073893]});
var query = {
coordinates: {$geoWithin: {$centerSphere: [[-118.240013, 34.073893], 0.44915760491198753]}},
diff --git a/jstests/core/geo_s2dupe_points.js b/jstests/core/geo_s2dupe_points.js
index 18550b0bbbb..2514cdbf4c1 100644
--- a/jstests/core/geo_s2dupe_points.js
+++ b/jstests/core/geo_s2dupe_points.js
@@ -7,7 +7,7 @@
// ]
t = db.geo_s2dupe_points;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
function testDuplicates(shapeName, shapeWithDupes, shapeWithoutDupes) {
// insert a doc with dupes
diff --git a/jstests/core/geo_s2edgecases.js b/jstests/core/geo_s2edgecases.js
index 6e4633f58c8..3dabfdf0bcb 100644
--- a/jstests/core/geo_s2edgecases.js
+++ b/jstests/core/geo_s2edgecases.js
@@ -51,7 +51,7 @@ penguin2 = {
};
t.insert({geo: penguin2});
-t.createIndex({geo: "2dsphere", nonGeo: 1});
+t.ensureIndex({geo: "2dsphere", nonGeo: 1});
res = t.find({"geo": {"$geoIntersects": {"$geometry": roundworldpoint}}});
assert.eq(res.count(), 2);
diff --git a/jstests/core/geo_s2exact.js b/jstests/core/geo_s2exact.js
index 92ce551d873..2c8571c0830 100644
--- a/jstests/core/geo_s2exact.js
+++ b/jstests/core/geo_s2exact.js
@@ -5,7 +5,7 @@ t.drop();
function test(geometry) {
t.insert({geo: geometry});
assert.eq(1, t.find({geo: geometry}).itcount(), tojson(geometry));
- t.createIndex({geo: "2dsphere"});
+ t.ensureIndex({geo: "2dsphere"});
assert.eq(1, t.find({geo: geometry}).itcount(), tojson(geometry));
t.dropIndex({geo: "2dsphere"});
}
diff --git a/jstests/core/geo_s2explain.js b/jstests/core/geo_s2explain.js
index 9ae76163485..842c6eb22c8 100644
--- a/jstests/core/geo_s2explain.js
+++ b/jstests/core/geo_s2explain.js
@@ -11,7 +11,7 @@ var point1 = {loc: {type: "Point", coordinates: [10, 10]}};
var point2 = {loc: {type: "Point", coordinates: [10.001, 10]}};
assert.commandWorked(t.insert([point1, point2]));
-assert.commandWorked(t.createIndex({loc: "2dsphere"}));
+assert.commandWorked(t.ensureIndex({loc: "2dsphere"}));
var explain = t.find({loc: {$nearSphere: {type: "Point", coordinates: [10, 10]}}})
.limit(1)
diff --git a/jstests/core/geo_s2holesameasshell.js b/jstests/core/geo_s2holesameasshell.js
index 0b3f8ea35ec..5407fe45c26 100644
--- a/jstests/core/geo_s2holesameasshell.js
+++ b/jstests/core/geo_s2holesameasshell.js
@@ -1,7 +1,7 @@
// If polygons have holes, the holes cannot be equal to the entire geometry.
var t = db.geo_s2holessameasshell;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
var centerPoint = {"type": "Point", "coordinates": [0.5, 0.5]};
var edgePoint = {"type": "Point", "coordinates": [0, 0.5]};
diff --git a/jstests/core/geo_s2index.js b/jstests/core/geo_s2index.js
index 328b43d04ab..ecc20c7e637 100644
--- a/jstests/core/geo_s2index.js
+++ b/jstests/core/geo_s2index.js
@@ -10,7 +10,7 @@ someline = {
"coordinates": [[40, 5], [40, 5], [40, 5], [41, 6], [41, 6]]
};
t.insert({geo: someline, nonGeo: "someline"});
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
foo = t.find({geo: {$geoIntersects: {$geometry: {type: "Point", coordinates: [40, 5]}}}}).next();
assert.eq(foo.geo, someline);
t.dropIndex({geo: "2dsphere"});
@@ -56,7 +56,7 @@ somepoly = {
};
t.insert({geo: somepoly, nonGeo: "somepoly"});
-var res = t.createIndex({geo: "2dsphere", nonGeo: 1});
+var res = t.ensureIndex({geo: "2dsphere", nonGeo: 1});
// We have a point without any geo data. Don't error.
assert.commandWorked(res);
@@ -86,7 +86,7 @@ assert.eq(res.itcount(), 1);
// Don't crash mongod if we give it bad input.
t.drop();
-t.createIndex({loc: "2dsphere", x: 1});
+t.ensureIndex({loc: "2dsphere", x: 1});
t.save({loc: [0, 0]});
assert.throws(function() {
return t.count({loc: {$foo: [0, 0]}});
@@ -102,7 +102,7 @@ assert.throws(function() {
// If we specify a datum, it has to be valid (WGS84).
t.drop();
-t.createIndex({loc: "2dsphere"});
+t.ensureIndex({loc: "2dsphere"});
res = t.insert({
loc: {type: 'Point', coordinates: [40, 5], crs: {type: 'name', properties: {name: 'EPSG:2000'}}}
});
@@ -127,36 +127,36 @@ assert.commandWorked(res);
// 0 <= coarsestIndexedLevel <= finestIndexedLevel <= 30.
t.drop();
t.save({loc: [0, 0]});
-res = t.createIndex({loc: "2dsphere"}, {finestIndexedLevel: 17, coarsestIndexedLevel: 5});
+res = t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 17, coarsestIndexedLevel: 5});
assert.commandWorked(res);
// Ensure the index actually works at a basic level
assert.neq(null, t.findOne({loc: {$geoNear: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}));
t.drop();
t.save({loc: [0, 0]});
-res = t.createIndex({loc: "2dsphere"}, {finestIndexedLevel: 31, coarsestIndexedLevel: 5});
+res = t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 31, coarsestIndexedLevel: 5});
assert.commandFailed(res);
t.drop();
t.save({loc: [0, 0]});
-res = t.createIndex({loc: "2dsphere"}, {finestIndexedLevel: 30, coarsestIndexedLevel: 0});
+res = t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 30, coarsestIndexedLevel: 0});
assert.commandWorked(res);
// Ensure the index actually works at a basic level
assert.neq(null, t.findOne({loc: {$geoNear: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}));
t.drop();
t.save({loc: [0, 0]});
-res = t.createIndex({loc: "2dsphere"}, {finestIndexedLevel: 30, coarsestIndexedLevel: -1});
+res = t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 30, coarsestIndexedLevel: -1});
assert.commandFailed(res);
// SERVER-21491 Verify that 2dsphere index options require correct types.
-res = t.createIndex({loc: '2dsphere'}, {'2dsphereIndexVersion': 'NOT_A_NUMBER'});
+res = t.ensureIndex({loc: '2dsphere'}, {'2dsphereIndexVersion': 'NOT_A_NUMBER'});
assert.commandFailed(res);
-res = t.createIndex({loc: '2dsphere'}, {finestIndexedLevel: 'NOT_A_NUMBER'});
+res = t.ensureIndex({loc: '2dsphere'}, {finestIndexedLevel: 'NOT_A_NUMBER'});
assert.commandFailedWithCode(res, ErrorCodes.TypeMismatch);
-res = t.createIndex({loc: '2dsphere'}, {coarsestIndexedLevel: 'NOT_A_NUMBER'});
+res = t.ensureIndex({loc: '2dsphere'}, {coarsestIndexedLevel: 'NOT_A_NUMBER'});
assert.commandFailedWithCode(res, ErrorCodes.TypeMismatch);
// Ensure polygon which previously triggered an assertion error in SERVER-19674
diff --git a/jstests/core/geo_s2indexoldformat.js b/jstests/core/geo_s2indexoldformat.js
index ffe472464d4..43974f695cb 100644
--- a/jstests/core/geo_s2indexoldformat.js
+++ b/jstests/core/geo_s2indexoldformat.js
@@ -9,7 +9,7 @@ t.insert({geo: [41, 6], nonGeo: ["pointB"]});
t.insert({geo: [41, 6]});
t.insert({geo: {x: 40.6, y: 5.4}});
-t.createIndex({geo: "2dsphere", nonGeo: 1});
+t.ensureIndex({geo: "2dsphere", nonGeo: 1});
res = t.find({"geo": {"$geoIntersects": {"$geometry": {x: 40, y: 5}}}});
assert.eq(res.count(), 1);
diff --git a/jstests/core/geo_s2indexversion1.js b/jstests/core/geo_s2indexversion1.js
index 2df90bb1235..a06670ab220 100644
--- a/jstests/core/geo_s2indexversion1.js
+++ b/jstests/core/geo_s2indexversion1.js
@@ -15,27 +15,27 @@ coll.drop();
//
var res;
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": -1});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": -1});
assert.commandFailed(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 0});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 0});
assert.commandFailed(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 4});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 4});
assert.commandFailed(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": Infinity});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": Infinity});
assert.commandFailed(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": "foo"});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": "foo"});
assert.commandFailed(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": {a: 1}});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": {a: 1}});
assert.commandFailed(res);
coll.drop();
@@ -43,31 +43,31 @@ coll.drop();
// Index build should succeed for valid values of "2dsphereIndexVersion".
//
-res = coll.createIndex({geo: "2dsphere"});
+res = coll.ensureIndex({geo: "2dsphere"});
assert.commandWorked(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1});
assert.commandWorked(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberInt(1)});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberInt(1)});
assert.commandWorked(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberLong(1)});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberLong(1)});
assert.commandWorked(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2});
assert.commandWorked(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberInt(2)});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberInt(2)});
assert.commandWorked(res);
coll.drop();
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberLong(2)});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberLong(2)});
assert.commandWorked(res);
coll.drop();
@@ -75,7 +75,7 @@ coll.drop();
// {2dsphereIndexVersion: 3} should be the default for new indexes.
//
-res = coll.createIndex({geo: "2dsphere"});
+res = coll.ensureIndex({geo: "2dsphere"});
assert.commandWorked(res);
var specObj = coll.getIndexes().filter(function(z) {
return z.name == "geo_2dsphere";
@@ -85,26 +85,26 @@ coll.drop();
//
// Two index specs are considered equivalent if they differ only in '2dsphereIndexVersion', and
-// createIndex() should become a no-op on repeated requests that only differ in this way.
+// ensureIndex() should become a no-op on repeated requests that only differ in this way.
//
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
assert.eq(1, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}));
assert.eq(2, coll.getIndexes().length);
coll.drop();
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
assert.eq(1, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1}));
assert.eq(2, coll.getIndexes().length);
-assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}));
assert.eq(2, coll.getIndexes().length);
coll.drop();
@@ -175,7 +175,7 @@ var geometryCollectionDoc = {
};
// {2dsphereIndexVersion: 2} indexes allow all supported GeoJSON objects.
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2});
assert.commandWorked(res);
res = coll.insert(pointDoc);
assert.commandWorked(res);
@@ -194,7 +194,7 @@ assert.commandWorked(res);
coll.drop();
// {2dsphereIndexVersion: 1} indexes allow only Point, LineString, and Polygon.
-res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1});
+res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1});
assert.commandWorked(res);
res = coll.insert(pointDoc);
assert.commandWorked(res);
diff --git a/jstests/core/geo_s2intersection.js b/jstests/core/geo_s2intersection.js
index 50f26a6aa83..25479a58349 100644
--- a/jstests/core/geo_s2intersection.js
+++ b/jstests/core/geo_s2intersection.js
@@ -1,6 +1,6 @@
var t = db.geo_s2intersectinglines;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
/**All the tests in this file are generally confirming intersections based upon
* these three geo objects.
@@ -143,7 +143,7 @@ assert.eq(result[0]['name'], 'canonPoly');
// Case 12: Make sure that we properly handle and $and of two
// $geoIntersects predicates.
t.drop();
-t.createIndex({a: "2dsphere"});
+t.ensureIndex({a: "2dsphere"});
t.insert({a: {type: "Polygon", coordinates: [[[0, 0], [3, 6], [6, 0], [0, 0]]]}});
var firstPoint = {$geometry: {type: "Point", coordinates: [3.0, 1.0]}};
diff --git a/jstests/core/geo_s2largewithin.js b/jstests/core/geo_s2largewithin.js
index 156b711bdff..4723bb4833e 100644
--- a/jstests/core/geo_s2largewithin.js
+++ b/jstests/core/geo_s2largewithin.js
@@ -5,7 +5,7 @@
// ]
t = db.geo_s2largewithin;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
testPoint = {
name: "origin",
diff --git a/jstests/core/geo_s2meridian.js b/jstests/core/geo_s2meridian.js
index 5842000e998..47f4fb08a6a 100644
--- a/jstests/core/geo_s2meridian.js
+++ b/jstests/core/geo_s2meridian.js
@@ -1,6 +1,6 @@
t = db.geo_s2meridian;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
/**
* Test 1: check that intersection works on the meridian. We insert a line
@@ -26,7 +26,7 @@ result = t.find({geo: {$geoIntersects: {$geometry: lineAlongMeridian}}});
assert.eq(result.itcount(), 1);
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
/*
* Test 2: check that within work across the meridian. We insert points
* on the meridian, and immediately on either side, and confirm that a poly
@@ -55,7 +55,7 @@ result = t.find({geo: {$geoWithin: {$geometry: meridianCrossingPoly}}});
assert.eq(result.itcount(), 3);
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
/*
* Test 3: Check that near works around the meridian. Insert two points, one
* closer, but across the meridian, and confirm they both come back, and
diff --git a/jstests/core/geo_s2multi.js b/jstests/core/geo_s2multi.js
index 9f4208d51aa..28034ad8ba6 100644
--- a/jstests/core/geo_s2multi.js
+++ b/jstests/core/geo_s2multi.js
@@ -1,7 +1,7 @@
t = db.geo_s2multi;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
// Let's try the examples in the GeoJSON spec.
// @tags: [
diff --git a/jstests/core/geo_s2near.js b/jstests/core/geo_s2near.js
index 2cd1df5cbbc..c61e16927ff 100644
--- a/jstests/core/geo_s2near.js
+++ b/jstests/core/geo_s2near.js
@@ -14,7 +14,7 @@ goldenPoint = {
coordinates: [31.0, 41.0]
};
t.insert({geo: goldenPoint});
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
resNear =
t.aggregate([
{$geoNear: {near: [30, 40], distanceField: "d", spherical: true, includeLocs: "loc"}},
@@ -40,7 +40,7 @@ origin = {
"coordinates": [lng, lat]
};
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
// Near only works when the query is a point.
someline = {
diff --git a/jstests/core/geo_s2nearComplex.js b/jstests/core/geo_s2nearComplex.js
index 40bc9b72445..d7f4fffabc1 100644
--- a/jstests/core/geo_s2nearComplex.js
+++ b/jstests/core/geo_s2nearComplex.js
@@ -6,7 +6,7 @@
var t = db.get_s2nearcomplex;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
/* Short names for math operations */
Random.setRandomSeed();
@@ -176,7 +176,7 @@ print("Total points:");
print(t.find(query).itcount());
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
// Test a uniform distribution with 5 gaps each with 10 points missing.
uniformPointsWithGaps(origin, 1000, 1, 10.0, 5, 10);
@@ -188,7 +188,7 @@ print("Total points:");
print(t.find(query).itcount());
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
// Test a uniform distribution with 5 clusters each with between 10 and 100 points.
uniformPointsWithClusters(origin, 1000, 1, 10.0, 5, 10, 100);
@@ -201,7 +201,7 @@ print("Total points:");
print(t.find(query).itcount());
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
// Test a uniform near search with origin around the pole.
@@ -225,7 +225,7 @@ print(t.find({geo: {$geoNear: {$geometry: originGeo}}})
assert.eq(t.find({geo: {$geoNear: {$geometry: originGeo}}}).itcount(), 50);
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
// Center point near the meridian
originGeo = {
@@ -247,7 +247,7 @@ print(t.find({geo: {$geoNear: {$geometry: originGeo}}})
assert.eq(t.find({geo: {$geoNear: {$geometry: originGeo}}}).itcount(), 50);
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
// Center point near the negative meridian
originGeo = {
@@ -270,7 +270,7 @@ assert.eq(t.find({geo: {$near: {$geometry: originGeo}}}).itcount(), 50);
// Near search with points that are really far away.
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
originGeo = {
type: "Point",
coordinates: [0.0, 0.0]
diff --git a/jstests/core/geo_s2near_equator_opposite.js b/jstests/core/geo_s2near_equator_opposite.js
index 4b028baf43c..de196ea70eb 100644
--- a/jstests/core/geo_s2near_equator_opposite.js
+++ b/jstests/core/geo_s2near_equator_opposite.js
@@ -12,7 +12,7 @@ t.drop();
t.insert({loc: {type: 'Point', coordinates: [0, 0]}});
t.insert({loc: {type: 'Point', coordinates: [-1, 0]}});
-t.createIndex({loc: '2dsphere'});
+t.ensureIndex({loc: '2dsphere'});
// upper bound for half of earth's circumference in meters
var dist = 40075000 / 2 + 1;
diff --git a/jstests/core/geo_s2nearcorrect.js b/jstests/core/geo_s2nearcorrect.js
index 80ece4223d2..54552a4bee5 100644
--- a/jstests/core/geo_s2nearcorrect.js
+++ b/jstests/core/geo_s2nearcorrect.js
@@ -10,7 +10,7 @@ longline = {
"coordinates": [[0, 0], [179, 89]]
};
t.insert({geo: longline});
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
origin = {
"type": "Point",
"coordinates": [45, 45]
diff --git a/jstests/core/geo_s2nearwithin.js b/jstests/core/geo_s2nearwithin.js
index eb334e89aff..8018dfec575 100644
--- a/jstests/core/geo_s2nearwithin.js
+++ b/jstests/core/geo_s2nearwithin.js
@@ -18,7 +18,7 @@ origin = {
"coordinates": [0, 0]
};
-assert.commandWorked(t.createIndex({geo: "2dsphere"}));
+assert.commandWorked(t.ensureIndex({geo: "2dsphere"}));
// Near requires an index, and 2dsphere is an index. Spherical isn't
// specified so this doesn't work.
let res = assert.commandFailedWithCode(t.runCommand("aggregate", {
diff --git a/jstests/core/geo_s2nongeoarray.js b/jstests/core/geo_s2nongeoarray.js
index 5fb5c59f1af..4242a9f38e9 100644
--- a/jstests/core/geo_s2nongeoarray.js
+++ b/jstests/core/geo_s2nongeoarray.js
@@ -11,19 +11,19 @@ var data = {geo: oldPoint, nonGeo: [123, 456], otherNonGeo: [{b: [1, 2]}, {b: [3
t.drop();
assert.commandWorked(t.insert(data));
-assert.commandWorked(t.createIndex({otherNonGeo: 1}));
+assert.commandWorked(t.ensureIndex({otherNonGeo: 1}));
assert.eq(1, t.find({otherNonGeo: {b: [1, 2]}}).itcount());
assert.eq(0, t.find({otherNonGeo: 1}).itcount());
assert.eq(1, t.find({'otherNonGeo.b': 1}).itcount());
t.drop();
t.insert(data);
-t.createIndex({geo: "2d", nonGeo: 1, otherNonGeo: 1});
+t.ensureIndex({geo: "2d", nonGeo: 1, otherNonGeo: 1});
assert.eq(t.find({nonGeo: 123, geo: {$nearSphere: oldPoint}}).itcount(), 1);
assert.eq(t.find({'otherNonGeo.b': 1, geo: {$nearSphere: oldPoint}}).itcount(), 1);
t.drop();
t.insert(data);
-t.createIndex({geo: "2dsphere", nonGeo: 1, otherNonGeo: 1});
+t.ensureIndex({geo: "2dsphere", nonGeo: 1, otherNonGeo: 1});
assert.eq(t.find({nonGeo: 123, geo: {$nearSphere: oldPoint}}).itcount(), 1);
assert.eq(t.find({'otherNonGeo.b': 1, geo: {$nearSphere: oldPoint}}).itcount(), 1);
diff --git a/jstests/core/geo_s2nonstring.js b/jstests/core/geo_s2nonstring.js
index a76a7cd073e..960f0c727a8 100644
--- a/jstests/core/geo_s2nonstring.js
+++ b/jstests/core/geo_s2nonstring.js
@@ -2,13 +2,13 @@
t = db.geo_s2nonstring;
t.drop();
-t.createIndex({geo: '2dsphere', x: 1});
+t.ensureIndex({geo: '2dsphere', x: 1});
t.save({geo: {type: 'Point', coordinates: [0, 0]}, x: 'a'});
t.save({geo: {type: 'Point', coordinates: [0, 0]}, x: 5});
t.drop();
-t.createIndex({geo: '2dsphere', x: 1});
+t.ensureIndex({geo: '2dsphere', x: 1});
t.save({geo: {type: 'Point', coordinates: [0, 0]}, x: 'a'});
t.save({geo: {type: 'Point', coordinates: [0, 0]}});
diff --git a/jstests/core/geo_s2nopoints.js b/jstests/core/geo_s2nopoints.js
index 7b3a3b970a7..0d2afdb1672 100644
--- a/jstests/core/geo_s2nopoints.js
+++ b/jstests/core/geo_s2nopoints.js
@@ -2,7 +2,7 @@
t = db.geo_s2nopoints;
t.drop();
-t.createIndex({loc: "2dsphere", x: 1});
+t.ensureIndex({loc: "2dsphere", x: 1});
assert.eq(
0,
t.count({loc: {$near: {$geometry: {type: 'Point', coordinates: [0, 0]}, $maxDistance: 10}}}));
diff --git a/jstests/core/geo_s2oddshapes.js b/jstests/core/geo_s2oddshapes.js
index 9ebe6be7ed3..0cc60a661a4 100644
--- a/jstests/core/geo_s2oddshapes.js
+++ b/jstests/core/geo_s2oddshapes.js
@@ -6,7 +6,7 @@
// ]
var t = db.geo_s2oddshapes;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
var testPoint = {name: "origin", geo: {type: "Point", coordinates: [0.0, 0.0]}};
@@ -58,7 +58,7 @@ assert.eq(result.itcount(), 3);
// Test a poly that is the size of half the earth.
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
var insidePoint = {name: "inside", geo: {type: "Point", name: "inside", coordinates: [100.0, 0.0]}};
@@ -84,7 +84,7 @@ assert.eq(point.name, 'inside');
// Test a poly that is very small. A couple meters around.
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
insidePoint = {
name: "inside",
diff --git a/jstests/core/geo_s2ordering.js b/jstests/core/geo_s2ordering.js
index 9e53cafb981..8ef84905b75 100644
--- a/jstests/core/geo_s2ordering.js
+++ b/jstests/core/geo_s2ordering.js
@@ -35,7 +35,7 @@ function makepoints(needle) {
}
function runTest(index) {
- assert.commandWorked(coll.createIndex(index));
+ assert.commandWorked(coll.ensureIndex(index));
const cursor =
coll.find({nongeo: needle, geo: {$within: {$centerSphere: [[0, 0], Math.PI / 180.0]}}});
const stats = cursor.explain("executionStats").executionStats;
diff --git a/jstests/core/geo_s2overlappingpolys.js b/jstests/core/geo_s2overlappingpolys.js
index 3cc1f254a37..9dd7125349a 100644
--- a/jstests/core/geo_s2overlappingpolys.js
+++ b/jstests/core/geo_s2overlappingpolys.js
@@ -6,7 +6,7 @@
var t = db.geo_s2overlappingpolys;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
var minError = 0.8e-13;
diff --git a/jstests/core/geo_s2polywithholes.js b/jstests/core/geo_s2polywithholes.js
index e37606465f6..c20da5a34aa 100644
--- a/jstests/core/geo_s2polywithholes.js
+++ b/jstests/core/geo_s2polywithholes.js
@@ -5,7 +5,7 @@
*/
var t = db.geo_s2weirdpolys;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
var centerPoint = {"type": "Point", "coordinates": [0.5, 0.5]};
var edgePoint = {"type": "Point", "coordinates": [0, 0.5]};
diff --git a/jstests/core/geo_s2selfintersectingpoly.js b/jstests/core/geo_s2selfintersectingpoly.js
index 0ac522fa6f7..0887f850fe3 100644
--- a/jstests/core/geo_s2selfintersectingpoly.js
+++ b/jstests/core/geo_s2selfintersectingpoly.js
@@ -1,6 +1,6 @@
var t = db.geo_s2selfintersectingpoly;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
var intersectingPolygon = {
"type": "Polygon",
diff --git a/jstests/core/geo_s2sparse.js b/jstests/core/geo_s2sparse.js
index 1a9a3b67b9b..d058afb9f9b 100644
--- a/jstests/core/geo_s2sparse.js
+++ b/jstests/core/geo_s2sparse.js
@@ -15,7 +15,7 @@ var indexName = 'geo_2dsphere_nonGeo_1';
// Clean up.
coll.drop();
-coll.createIndex(indexSpec);
+coll.ensureIndex(indexSpec);
var bulkInsertDocs = function(coll, numDocs, makeDocFn) {
print("Bulk inserting " + numDocs + " documents");
@@ -77,7 +77,7 @@ assert.eq(N + N, coll.validate().keysPerIndex[indexName]);
//
coll.drop();
-coll.createIndex(indexSpec, {"2dsphereIndexVersion": 1});
+coll.ensureIndex(indexSpec, {"2dsphereIndexVersion": 1});
// Insert N documents with the geo field.
bulkInsertDocs(coll, N, function(i) {
@@ -101,7 +101,7 @@ assert.eq(N + N, coll.validate().keysPerIndex[indexName]);
// Clean up.
coll.drop();
-coll.createIndex({geo: "2dsphere", otherGeo: "2dsphere"});
+coll.ensureIndex({geo: "2dsphere", otherGeo: "2dsphere"});
indexName = 'geo_2dsphere_otherGeo_2dsphere';
diff --git a/jstests/core/geo_s2twofields.js b/jstests/core/geo_s2twofields.js
index 160b5f513e1..73666f2bf5e 100644
--- a/jstests/core/geo_s2twofields.js
+++ b/jstests/core/geo_s2twofields.js
@@ -55,7 +55,7 @@ function timeWithoutAndWithAnIndex(index, query) {
var withoutTime = semiRigorousTime(function() {
return t.find(query).explain("executionStats").executionStats.executionTimeMillis;
});
- t.createIndex(index);
+ t.ensureIndex(index);
var withTime = semiRigorousTime(function() {
return t.find(query).explain("executionStats").executionStats.executionTimeMillis;
});
diff --git a/jstests/core/geo_s2validindex.js b/jstests/core/geo_s2validindex.js
index 444346def14..4c024d2d585 100644
--- a/jstests/core/geo_s2validindex.js
+++ b/jstests/core/geo_s2validindex.js
@@ -6,19 +6,19 @@ var coll = db.getCollection("twodspherevalid");
// Valid index
coll.drop();
-assert.commandWorked(coll.createIndex({geo: "2dsphere", other: 1}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere", other: 1}));
// Valid index
coll.drop();
-assert.commandWorked(coll.createIndex({geo: "2dsphere", other: 1, geo2: "2dsphere"}));
+assert.commandWorked(coll.ensureIndex({geo: "2dsphere", other: 1, geo2: "2dsphere"}));
// Invalid index, using hash with 2dsphere
coll.drop();
-assert.commandFailed(coll.createIndex({geo: "2dsphere", other: "hash"}));
+assert.commandFailed(coll.ensureIndex({geo: "2dsphere", other: "hash"}));
// Invalid index, using 2d with 2dsphere
coll.drop();
-assert.commandFailed(coll.createIndex({geo: "2dsphere", other: "2d"}));
+assert.commandFailed(coll.ensureIndex({geo: "2dsphere", other: "2d"}));
jsTest.log("Success!");
diff --git a/jstests/core/geo_s2within.js b/jstests/core/geo_s2within.js
index 4f908a4f303..c32eb4fd612 100644
--- a/jstests/core/geo_s2within.js
+++ b/jstests/core/geo_s2within.js
@@ -4,7 +4,7 @@
// ]
t = db.geo_s2within;
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
somepoly = {
"type": "Polygon",
@@ -19,7 +19,7 @@ res = t.find({"geo": {"$within": {"$geometry": somepoly}}});
assert.eq(res.itcount(), 1);
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
somepoly = {
"type": "Polygon",
"coordinates": [
diff --git a/jstests/core/geo_small_large.js b/jstests/core/geo_small_large.js
index 94d5298081e..5cfa3e68e0f 100644
--- a/jstests/core/geo_small_large.js
+++ b/jstests/core/geo_small_large.js
@@ -56,7 +56,7 @@ for (var i = 0; i < scales.length; i++) {
var t = db["geo_small_large"];
t.drop();
- t.createIndex({p: "2d"}, {min: min, max: max, bits: bits});
+ t.ensureIndex({p: "2d"}, {min: min, max: max, bits: bits});
var outPoints = 0;
var inPoints = 0;
diff --git a/jstests/core/geo_sort1.js b/jstests/core/geo_sort1.js
index 3e9ee494812..22e185d0106 100644
--- a/jstests/core/geo_sort1.js
+++ b/jstests/core/geo_sort1.js
@@ -12,7 +12,7 @@ for (x = 0; x < 10; x++) {
}
}
-t.createIndex({loc: "2d", foo: 1});
+t.ensureIndex({loc: "2d", foo: 1});
q = t.find({loc: {$near: [5, 5]}, foo: {$gt: 20}});
m = function(z) {
diff --git a/jstests/core/geo_uniqueDocs.js b/jstests/core/geo_uniqueDocs.js
index b6eaf4e0501..88162e42498 100644
--- a/jstests/core/geo_uniqueDocs.js
+++ b/jstests/core/geo_uniqueDocs.js
@@ -11,7 +11,7 @@ t.drop();
assert.commandWorked(t.save({locs: [[0, 2], [3, 4]]}));
assert.commandWorked(t.save({locs: [[6, 8], [10, 10]]}));
-assert.commandWorked(t.createIndex({locs: '2d'}));
+assert.commandWorked(t.ensureIndex({locs: '2d'}));
// $geoNear tests
// uniqueDocs option is ignored.
diff --git a/jstests/core/geo_uniqueDocs2.js b/jstests/core/geo_uniqueDocs2.js
index 1486023b73f..9e0b4a0a284 100644
--- a/jstests/core/geo_uniqueDocs2.js
+++ b/jstests/core/geo_uniqueDocs2.js
@@ -12,7 +12,7 @@ t = db[collName];
t.drop();
t.save({loc: [[20, 30], [40, 50]]});
-t.createIndex({loc: '2d'});
+t.ensureIndex({loc: '2d'});
// Check exact matches of different locations.
assert.eq(1, t.count({loc: [20, 30]}));
@@ -109,5 +109,5 @@ for (i = 0; i < 10000; ++i) {
}
arr.push([100, 100]);
t.save({loc: arr});
-t.createIndex({loc: '2d'});
+t.ensureIndex({loc: '2d'});
assert.eq(1, t.count({loc: {$within: {$center: [[99, 99], 5]}}}));
diff --git a/jstests/core/geo_update.js b/jstests/core/geo_update.js
index 015e56e34a5..21cf42d2208 100644
--- a/jstests/core/geo_update.js
+++ b/jstests/core/geo_update.js
@@ -11,7 +11,7 @@
var coll = db.testGeoUpdate;
coll.drop();
-coll.createIndex({loc: "2d"});
+coll.ensureIndex({loc: "2d"});
// Test normal update
print("Updating...");
diff --git a/jstests/core/geo_update1.js b/jstests/core/geo_update1.js
index cd23e65b7b7..a4de04fbd93 100644
--- a/jstests/core/geo_update1.js
+++ b/jstests/core/geo_update1.js
@@ -11,7 +11,7 @@ for (var x = 0; x < 10; x++) {
}
}
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
function p() {
print("--------------");
diff --git a/jstests/core/geo_update2.js b/jstests/core/geo_update2.js
index d67b3a9bcc1..f1b94925cb7 100644
--- a/jstests/core/geo_update2.js
+++ b/jstests/core/geo_update2.js
@@ -11,7 +11,7 @@ for (var x = 0; x < 10; x++) {
}
}
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
function p() {
print("--------------");
diff --git a/jstests/core/geo_update_btree.js b/jstests/core/geo_update_btree.js
index 7a58362fe18..8cf711a9e48 100644
--- a/jstests/core/geo_update_btree.js
+++ b/jstests/core/geo_update_btree.js
@@ -10,7 +10,7 @@
var coll = db.getCollection("jstests_geo_update_btree");
coll.drop();
-coll.createIndex({loc: '2d'});
+coll.ensureIndex({loc: '2d'});
var big = new Array(3000).toString();
diff --git a/jstests/core/geo_update_btree2.js b/jstests/core/geo_update_btree2.js
index e37dbb190e1..3bc0a7c9760 100644
--- a/jstests/core/geo_update_btree2.js
+++ b/jstests/core/geo_update_btree2.js
@@ -28,7 +28,7 @@ var status = function(msg) {
var coll = db.getCollection("jstests_geo_update_btree2");
coll.drop();
-coll.createIndex({loc: '2d'});
+coll.ensureIndex({loc: '2d'});
status("Inserting points...");
diff --git a/jstests/core/geo_update_dedup.js b/jstests/core/geo_update_dedup.js
index 3938204c70e..34e9aff30dd 100644
--- a/jstests/core/geo_update_dedup.js
+++ b/jstests/core/geo_update_dedup.js
@@ -13,7 +13,7 @@ var t = db.jstests_geo_update_dedup;
// 2d index with $near
t.drop();
-t.createIndex({locs: "2d"});
+t.ensureIndex({locs: "2d"});
t.save({locs: [[49.999, 49.999], [50.0, 50.0], [50.001, 50.001]]});
var q = {locs: {$near: [50.0, 50.0]}};
@@ -24,7 +24,7 @@ assert.eq(1, res.nMatched);
assert.eq(1, t.findOne().touchCount);
t.drop();
-t.createIndex({locs: "2d"});
+t.ensureIndex({locs: "2d"});
t.save({locs: [{x: 49.999, y: 49.999}, {x: 50.0, y: 50.0}, {x: 50.001, y: 50.001}]});
res = t.update({locs: {$near: {x: 50.0, y: 50.0}}}, {$inc: {touchCount: 1}});
assert.eq(1, res.nMatched);
@@ -32,7 +32,7 @@ assert.eq(1, t.findOne().touchCount);
// 2d index with $within
t.drop();
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
t.save({loc: [[0, 0], [1, 1]]});
res = t.update({loc: {$within: {$center: [[0, 0], 2]}}}, {$inc: {touchCount: 1}}, false, true);
@@ -41,7 +41,7 @@ assert.eq(1, t.findOne().touchCount);
// 2dsphere index with $geoNear
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
var x = {
"type": "Polygon",
"coordinates": [[[49.999, 49.999], [50.0, 50.0], [50.001, 50.001], [49.999, 49.999]]]
@@ -62,7 +62,7 @@ var locdata = [
{geo: {type: "Point", coordinates: [50.001, 50.001]}}
];
t.save({locdata: locdata, count: 0});
-t.createIndex({"locdata.geo": "2dsphere"});
+t.ensureIndex({"locdata.geo": "2dsphere"});
res = t.update({"locdata.geo": {$geoNear: {"type": "Point", "coordinates": [50.0, 50.0]}}},
{$inc: {touchCount: 1}},
diff --git a/jstests/core/geo_validate.js b/jstests/core/geo_validate.js
index 0518740c02e..cd839ef8f97 100644
--- a/jstests/core/geo_validate.js
+++ b/jstests/core/geo_validate.js
@@ -8,7 +8,7 @@
var coll = db.geo_validate;
coll.drop();
-coll.createIndex({geo: "2dsphere"});
+coll.ensureIndex({geo: "2dsphere"});
//
//
diff --git a/jstests/core/geoa.js b/jstests/core/geoa.js
index 52a9d79db3b..c1e0a2f796a 100644
--- a/jstests/core/geoa.js
+++ b/jstests/core/geoa.js
@@ -10,7 +10,7 @@ t.save({_id: 1, a: {loc: [5, 5]}});
t.save({_id: 2, a: {loc: [6, 6]}});
t.save({_id: 3, a: {loc: [7, 7]}});
-t.createIndex({"a.loc": "2d"});
+t.ensureIndex({"a.loc": "2d"});
cur = t.find({"a.loc": {$near: [6, 6]}});
assert.eq(2, cur.next()._id, "A1");
diff --git a/jstests/core/geob.js b/jstests/core/geob.js
index b1093172618..6a7839253ee 100644
--- a/jstests/core/geob.js
+++ b/jstests/core/geob.js
@@ -17,7 +17,7 @@ t.save(a);
t.save(b);
t.save(c);
t.save(d);
-t.createIndex({p: "2d"});
+t.ensureIndex({p: "2d"});
let res = t.aggregate({$geoNear: {near: [0, 0], distanceField: "dis"}}).toArray();
diff --git a/jstests/core/geoc.js b/jstests/core/geoc.js
index 2c0948582c7..4264b6f9295 100644
--- a/jstests/core/geoc.js
+++ b/jstests/core/geoc.js
@@ -15,7 +15,7 @@ for (var i = 0; i < N; i++)
for (var i = 0; i < N; i++)
t.insert({loc: [-100 + Math.random(), -100 + Math.random()], z: 2});
-t.createIndex({loc: '2d'});
+t.ensureIndex({loc: '2d'});
function test(z, l) {
assert.lt(
diff --git a/jstests/core/geod.js b/jstests/core/geod.js
index 47b067809f8..fc6c37f1da3 100644
--- a/jstests/core/geod.js
+++ b/jstests/core/geod.js
@@ -2,7 +2,7 @@ var t = db.geod;
t.drop();
t.save({loc: [0, 0]});
t.save({loc: [0.5, 0]});
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
// do a few geoNears with different maxDistances. The first iteration
// should match no points in the dataset.
// @tags: [
diff --git a/jstests/core/geoe.js b/jstests/core/geoe.js
index 84bc34f7a74..9568e13dc08 100644
--- a/jstests/core/geoe.js
+++ b/jstests/core/geoe.js
@@ -22,7 +22,7 @@ t.insert({"_id": 12, "geo": [-122.3, 37.66]});
t.insert({"_id": 13, "geo": [-122.2435, 37.637072]});
t.insert({"_id": 14, "geo": [-122.289505, 37.695774]});
-t.createIndex({geo: "2d"});
+t.ensureIndex({geo: "2d"});
c = t.find({geo: {"$within": {"$box": [[-125.078461, 36.494473], [-120.320648, 38.905199]]}}});
assert.eq(11, c.count(), "A1");
diff --git a/jstests/core/geof.js b/jstests/core/geof.js
index 31e5439b158..ad15037db3b 100644
--- a/jstests/core/geof.js
+++ b/jstests/core/geof.js
@@ -14,7 +14,7 @@ t.insert({loc: [-0.7, -0.7]});
t.insert({loc: [-0.9, 0]});
t.insert({loc: [-0.9, 0]});
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
t.find({loc: {$near: [0, 0]}}).limit(2).forEach(function(o) {
// printjson(o);
diff --git a/jstests/core/geonear_cmd_input_validation.js b/jstests/core/geonear_cmd_input_validation.js
index 04f5e73fed0..2c3116c3a6d 100644
--- a/jstests/core/geonear_cmd_input_validation.js
+++ b/jstests/core/geonear_cmd_input_validation.js
@@ -6,7 +6,7 @@
// ]
var t = db.geonear_cmd_input_validation;
t.drop();
-t.createIndex({loc: "2dsphere"});
+t.ensureIndex({loc: "2dsphere"});
// The test matrix. Some combinations are not supported:
// 2d index and GeoJSON.
diff --git a/jstests/core/getmore_invalidated_documents.js b/jstests/core/getmore_invalidated_documents.js
index 4fc66fca5c8..3bc5458072e 100644
--- a/jstests/core/getmore_invalidated_documents.js
+++ b/jstests/core/getmore_invalidated_documents.js
@@ -23,7 +23,7 @@ var y;
// Case #1: Text search with deletion invalidation.
t.drop();
-assert.commandWorked(t.createIndex({a: "text"}));
+assert.commandWorked(t.ensureIndex({a: "text"}));
assert.commandWorked(t.insert({_id: 1, a: "bar"}));
assert.commandWorked(t.insert({_id: 2, a: "bar"}));
assert.commandWorked(t.insert({_id: 3, a: "bar"}));
@@ -41,7 +41,7 @@ assert(count === 0 || count === 1);
// Case #2: Text search with mutation invalidation.
t.drop();
-assert.commandWorked(t.createIndex({a: "text"}));
+assert.commandWorked(t.ensureIndex({a: "text"}));
assert.commandWorked(t.insert({_id: 1, a: "bar"}));
assert.commandWorked(t.insert({_id: 2, a: "bar"}));
assert.commandWorked(t.insert({_id: 3, a: "bar"}));
@@ -60,7 +60,7 @@ assert(!cursor.hasNext() || cursor.next()["a"] === "bar");
// Case #3: Merge sort with deletion invalidation.
t.drop();
-assert.commandWorked(t.createIndex({a: 1, b: 1}));
+assert.commandWorked(t.ensureIndex({a: 1, b: 1}));
assert.commandWorked(t.insert({a: 1, b: 1}));
assert.commandWorked(t.insert({a: 1, b: 2}));
assert.commandWorked(t.insert({a: 2, b: 3}));
@@ -77,7 +77,7 @@ assert(count === 1 || count === 2);
// Case #4: Merge sort with mutation invalidation.
t.drop();
-assert.commandWorked(t.createIndex({a: 1, b: 1}));
+assert.commandWorked(t.ensureIndex({a: 1, b: 1}));
assert.commandWorked(t.insert({a: 1, b: 1}));
assert.commandWorked(t.insert({a: 1, b: 2}));
assert.commandWorked(t.insert({a: 2, b: 3}));
@@ -101,7 +101,7 @@ assert(!cursor.hasNext());
// Case #5: 2d near with deletion invalidation.
t.drop();
-t.createIndex({geo: "2d"});
+t.ensureIndex({geo: "2d"});
for (x = -1; x < 1; x++) {
for (y = -1; y < 1; y++) {
assert.commandWorked(t.insert({geo: [x, y]}));
@@ -121,7 +121,7 @@ assert(cursor.hasNext());
// Case #6: 2dsphere near with deletion invalidation.
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
for (x = -1; x < 1; x++) {
for (y = -1; y < 1; y++) {
assert.commandWorked(t.insert({geo: [x, y]}));
@@ -141,7 +141,7 @@ assert(cursor.hasNext());
// Case #7: 2dsphere near with deletion invalidation (again).
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
for (x = 0; x < 6; x++) {
assert.commandWorked(t.insert({geo: [x, x]}));
}
@@ -159,7 +159,7 @@ assert.gte(cursor.itcount(), 0);
// Case #8: 2d near with mutation invalidation.
t.drop();
-t.createIndex({geo: "2d"});
+t.ensureIndex({geo: "2d"});
for (x = -1; x < 1; x++) {
for (y = -1; y < 1; y++) {
assert.commandWorked(t.insert({geo: [x, y]}));
@@ -182,7 +182,7 @@ assert(nextDoc.geo[0] === 0 || nextDoc.geo[1] === 0);
// Case #9: 2dsphere near with mutation invalidation.
t.drop();
-t.createIndex({geo: "2dsphere"});
+t.ensureIndex({geo: "2dsphere"});
for (x = -1; x < 1; x++) {
for (y = -1; y < 1; y++) {
assert.commandWorked(t.insert({geo: [x, y]}));
@@ -205,7 +205,7 @@ assert(nextDoc.geo[0] === 0 || nextDoc.geo[1] === 0);
// Case #10: sort with deletion invalidation.
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.insert({a: 1, b: 2});
t.insert({a: 3, b: 3});
t.insert({a: 2, b: 1});
@@ -222,7 +222,7 @@ if (cursor.hasNext()) {
// Case #11: sort with mutation invalidation.
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.insert({a: 1, b: 2});
t.insert({a: 3, b: 3});
t.insert({a: 2, b: 1});
diff --git a/jstests/core/hint1.js b/jstests/core/hint1.js
index d584144e641..6542f9752bc 100644
--- a/jstests/core/hint1.js
+++ b/jstests/core/hint1.js
@@ -2,7 +2,7 @@ p = db.jstests_hint1;
p.drop();
p.save({ts: new Date(1), cls: "entry", verticals: "alleyinsider", live: true});
-p.createIndex({ts: 1});
+p.ensureIndex({ts: 1});
assert.eq(
1,
diff --git a/jstests/core/idhack.js b/jstests/core/idhack.js
index 83a359f0f53..a884fecd920 100644
--- a/jstests/core/idhack.js
+++ b/jstests/core/idhack.js
@@ -41,7 +41,7 @@ assert.eq(1, explain.executionStats.totalKeysExamined);
assert(isIdhack(db, explain.queryPlanner.winningPlan));
// ID hack cannot be used with hint().
-t.createIndex({_id: 1, a: 1});
+t.ensureIndex({_id: 1, a: 1});
explain = t.find(query).hint({_id: 1, a: 1}).explain();
assert(!isIdhack(db, explain.queryPlanner.winningPlan));
diff --git a/jstests/core/in.js b/jstests/core/in.js
index ca8cd77b189..852f6bcbca4 100644
--- a/jstests/core/in.js
+++ b/jstests/core/in.js
@@ -17,7 +17,7 @@ assert.eq(1, t.find({a: {$in: [1]}}).itcount(), "A");
assert.eq(1, t.find({a: {$in: [2]}}).itcount(), "B");
assert.eq(2, t.find({a: {$in: [1, 2]}}).itcount(), "C");
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq(1, t.find({a: {$in: [1]}}).itcount(), "D");
assert.eq(1, t.find({a: {$in: [2]}}).itcount(), "E");
diff --git a/jstests/core/in2.js b/jstests/core/in2.js
index 6682bbc79c1..ddcee67ccd0 100644
--- a/jstests/core/in2.js
+++ b/jstests/core/in2.js
@@ -17,7 +17,7 @@ function go(name, index) {
t.save({a: 3, b: 1});
if (index)
- t.createIndex(index);
+ t.ensureIndex(index);
assert.eq(7, t.find({a: {$in: [1, 2]}}).count(), name + " A");
diff --git a/jstests/core/in3.js b/jstests/core/in3.js
index bd64329ded4..02680642939 100644
--- a/jstests/core/in3.js
+++ b/jstests/core/in3.js
@@ -19,5 +19,5 @@ function doTest() {
}
doTest();
-t.createIndex({key: 1});
+t.ensureIndex({key: 1});
doTest();
diff --git a/jstests/core/in4.js b/jstests/core/in4.js
index e916ca7c82d..df9eea2577b 100644
--- a/jstests/core/in4.js
+++ b/jstests/core/in4.js
@@ -33,5 +33,5 @@ function doTest() {
doTest();
// SERVER-1943 not fixed yet
-t.createIndex({key: 1});
+t.ensureIndex({key: 1});
doTest();
diff --git a/jstests/core/in5.js b/jstests/core/in5.js
index 80f37e6b473..2f92b057d6c 100644
--- a/jstests/core/in5.js
+++ b/jstests/core/in5.js
@@ -27,7 +27,7 @@ function go(fn) {
i = {};
i[fn] = 1;
- t.createIndex(i);
+ t.ensureIndex(i);
assert.eq(1, t.find(x).itcount(), "B1 - " + fn);
assert.eq(1, t.find(y).itcount(), "B2 - " + fn);
@@ -39,7 +39,7 @@ function go(fn) {
i = {};
i[fn + ".a"] = 1;
- t.createIndex(i);
+ t.ensureIndex(i);
assert.eq(2, t.getIndexes().length, "T3");
assert.eq(1, t.find(x).itcount(), "C1 - " + fn);
diff --git a/jstests/core/in6.js b/jstests/core/in6.js
index ab8322cfe0a..4ee06541b81 100644
--- a/jstests/core/in6.js
+++ b/jstests/core/in6.js
@@ -9,5 +9,5 @@ function doTest() {
}
doTest();
-t.createIndex({i: 1});
+t.ensureIndex({i: 1});
doTest();
diff --git a/jstests/core/in8.js b/jstests/core/in8.js
index f1b6188347c..a6bdc520926 100644
--- a/jstests/core/in8.js
+++ b/jstests/core/in8.js
@@ -8,7 +8,7 @@ function checkResults(query) {
assert.eq(4, t.find(query).itcount());
}
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
t.save({x: 'aa'});
t.save({x: 'ab'});
t.save({x: 'ac'});
diff --git a/jstests/core/inc1.js b/jstests/core/inc1.js
index 551d15e0f63..50a7892e5a4 100644
--- a/jstests/core/inc1.js
+++ b/jstests/core/inc1.js
@@ -26,7 +26,7 @@ test(5, "E");
t.update({_id: 1}, {$inc: {x: -1}});
test(4, "F");
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
t.update({_id: 1}, {$inc: {x: 1}});
test(5, "G");
diff --git a/jstests/core/inc2.js b/jstests/core/inc2.js
index debdfde82cb..6ff4842e254 100644
--- a/jstests/core/inc2.js
+++ b/jstests/core/inc2.js
@@ -17,7 +17,7 @@ assert.eq("1,2,3", order(), "A");
t.update({_id: 1}, {$inc: {x: 4}});
assert.eq("2,3,1", order(), "B");
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq("2,3,1", order(), "C");
t.update({_id: 3}, {$inc: {x: 4}});
diff --git a/jstests/core/index1.js b/jstests/core/index1.js
index 4c06bfe03fd..2efb9d22189 100644
--- a/jstests/core/index1.js
+++ b/jstests/core/index1.js
@@ -13,7 +13,7 @@ t.save(o);
assert(t.findOne().z.a == 17);
assert(t.findOne({z: {a: 17}}) == null);
-t.createIndex({"z.a": 1});
+t.ensureIndex({"z.a": 1});
assert(t.findOne().z.a == 17);
assert(t.findOne({z: {a: 17}}) == null);
diff --git a/jstests/core/index13.js b/jstests/core/index13.js
index 97a3a85f773..9979116ae51 100644
--- a/jstests/core/index13.js
+++ b/jstests/core/index13.js
@@ -40,7 +40,7 @@ index = {
'a.b': 1,
'a.c': 1
};
-t.createIndex(index);
+t.ensureIndex(index);
t.save({a: [{b: 1}, {c: 1}]});
t.save({a: [{b: 1, c: 1}]});
assert.eq(2, t.count());
@@ -68,7 +68,7 @@ index = {
'd.e': 1,
'd.f': 1
};
-t.createIndex(index);
+t.ensureIndex(index);
t.insert({a: [{b: 1}, {c: 1}], d: {e: 1, f: 1}});
t.insert({a: [{b: 1, c: 1}], d: {e: 1, f: 1}});
t.insert({a: {b: 1, c: 1}, d: [{e: 1, f: 1}]});
@@ -89,7 +89,7 @@ index = {
'a.b.c': 1,
'a.b.d': 1
};
-t.createIndex(index);
+t.ensureIndex(index);
t.insert({a: [{b: [{c: 1, d: 1}]}]});
t.insert({a: [{b: [{c: 1}, {d: 1}]}]});
assert.eq(2, t.count());
@@ -104,7 +104,7 @@ index = {
'a.b.x': 1,
'a.b.y': 1
};
-t.createIndex(index);
+t.ensureIndex(index);
t.save({a: {b: {x: 1, y: 1}}});
t.save({a: [{b: {x: 1}}, {b: {y: 1}}]});
t.save({a: [{b: [{x: 1}, {y: 1}]}]});
@@ -125,7 +125,7 @@ index = {
'a.b.x': 1,
'a.b.y': 1
};
-t.createIndex(index);
+t.ensureIndex(index);
// With $ne.
assertResults({a: {$ne: 4}, 'a.b': {$elemMatch: {x: 1, y: 1}}});
@@ -141,7 +141,7 @@ index = {
'a.b.d': 1,
'a.e.g': 1
};
-t.createIndex(index);
+t.ensureIndex(index);
t.save({a: {b: {c: 1, d: 1}, e: {f: 1, g: 1}}});
t.save({a: [{b: {c: 1}, e: {f: 1}}, {b: {d: 1}, e: {g: 1}}]});
t.save({a: [{b: {c: 1}}, {e: {f: 1}}, {b: {d: 1}}, {e: {g: 1}}]});
@@ -166,7 +166,7 @@ index = {
'a.b.d': 1,
'a.e.d': 1
};
-t.createIndex(index);
+t.ensureIndex(index);
t.save({a: [{b: [{c: 1, d: 1}]}, {e: [{c: 1, d: 1}]}]});
assert.eq(1, t.count());
diff --git a/jstests/core/index2.js b/jstests/core/index2.js
index 2c37c48c871..098bdc20529 100644
--- a/jstests/core/index2.js
+++ b/jstests/core/index2.js
@@ -40,7 +40,7 @@ assert(t.findOne({z: {a: 17}}).z.a == 17);
assert(t.find({z: {a: 17}}).length() == 2);
assert(t.find({z: {a: 18}}).length() == 1);
-t.createIndex({z: 1});
+t.ensureIndex({z: 1});
assert(t.findOne({z: {a: 17}}).z.a == 17);
assert(t.find({z: {a: 17}}).length() == 2);
diff --git a/jstests/core/index3.js b/jstests/core/index3.js
index cc5ad3b0796..6ae7c4b82dd 100644
--- a/jstests/core/index3.js
+++ b/jstests/core/index3.js
@@ -7,11 +7,11 @@ t.drop();
assert(t.getIndexes().length == 0);
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
t.save({name: "a"});
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
assert(t.getIndexes().length == 2);
diff --git a/jstests/core/index4.js b/jstests/core/index4.js
index 179bcdd9726..37ebce75a9c 100644
--- a/jstests/core/index4.js
+++ b/jstests/core/index4.js
@@ -14,10 +14,10 @@ t.save({name: "alleyinsider", instances: [{pool: "prod1"}, {pool: "dev1"}]});
t.save({name: "clusterstock", instances: [{pool: "dev1"}]});
// this should fail, not allowed -- we confirm that.
-t.createIndex({instances: {pool: 1}});
+t.ensureIndex({instances: {pool: 1}});
assert.eq(1, t.getIndexes().length, "no indexes other than _id should be here yet");
-t.createIndex({"instances.pool": 1});
+t.ensureIndex({"instances.pool": 1});
sleep(10);
diff --git a/jstests/core/index5.js b/jstests/core/index5.js
index 908b433c299..f46654c6602 100644
--- a/jstests/core/index5.js
+++ b/jstests/core/index5.js
@@ -22,5 +22,5 @@ t.save({a: 2});
validate();
-t.createIndex({a: -1});
+t.ensureIndex({a: -1});
validate();
diff --git a/jstests/core/index6.js b/jstests/core/index6.js
index 4626e9359ea..9adef9bf366 100644
--- a/jstests/core/index6.js
+++ b/jstests/core/index6.js
@@ -4,5 +4,5 @@ r = db.ed.db.index6;
r.drop();
r.save({comments: [{name: "eliot", foo: 1}]});
-r.createIndex({"comments.name": 1});
+r.ensureIndex({"comments.name": 1});
assert(r.findOne({"comments.name": "eliot"}));
diff --git a/jstests/core/index8.js b/jstests/core/index8.js
index 55ba8b805c9..5bae0bc6de2 100644
--- a/jstests/core/index8.js
+++ b/jstests/core/index8.js
@@ -8,9 +8,9 @@
t = db.jstests_index8;
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1}, true);
-t.createIndex({c: 1}, [false, "cIndex"]);
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1}, true);
+t.ensureIndex({c: 1}, [false, "cIndex"]);
checkIndexes = function(num) {
const indexes = t.getIndexes();
@@ -47,7 +47,7 @@ assert.eq(3, t.find().hint({b: 1}).toArray().length);
assert.eq(3, t.find().hint({a: 1}).toArray().length);
t.drop();
-t.createIndex({a: 1, b: -1}, true);
+t.ensureIndex({a: 1, b: -1}, true);
t.save({a: 2, b: 3});
t.save({a: 2, b: 3});
t.save({a: 2, b: 4});
@@ -55,13 +55,13 @@ t.save({a: 1, b: 3});
assert.eq(3, t.find().count());
t.drop();
-t.createIndex({a: 1}, true);
+t.ensureIndex({a: 1}, true);
t.save({a: [2, 3]});
t.save({a: 2});
assert.eq(1, t.find().count());
t.drop();
-t.createIndex({a: 1}, true);
+t.ensureIndex({a: 1}, true);
t.save({a: 2});
t.save({a: [1, 2, 3]});
t.save({a: [3, 2, 1]});
diff --git a/jstests/core/index_arr1.js b/jstests/core/index_arr1.js
index d6db3e621cd..cc6f1683bd1 100644
--- a/jstests/core/index_arr1.js
+++ b/jstests/core/index_arr1.js
@@ -11,11 +11,11 @@ t.insert({_id: 3, a: 5});
assert.eq(3, t.find({a: 5}).itcount(), "A1");
-t.createIndex({a: 1, "b.x": 1});
+t.ensureIndex({a: 1, "b.x": 1});
assert.eq(3, t.find({a: 5}).itcount(), "A2"); // SERVER-1082
assert.eq(2, t.getIndexes().length, "B1");
t.insert({_id: 4, a: 5, b: []});
-t.createIndex({a: 1, "b.a": 1, "b.c": 1});
+t.ensureIndex({a: 1, "b.a": 1, "b.c": 1});
assert.eq(3, t.getIndexes().length, "B2");
diff --git a/jstests/core/index_arr2.js b/jstests/core/index_arr2.js
index faca8be6337..cd0df2533d3 100644
--- a/jstests/core/index_arr2.js
+++ b/jstests/core/index_arr2.js
@@ -24,9 +24,9 @@ function test(withIndex) {
Z = t.find(query).count();
if (withIndex) {
- // t.createIndex( { 'a.b.c' : 1, 'created' : -1 } )
- // t.createIndex( { created : -1 } )
- t.createIndex({'a.b.c': 1}, {name: "x"});
+ // t.ensureIndex( { 'a.b.c' : 1, 'created' : -1 } )
+ // t.ensureIndex( { created : -1 } )
+ t.ensureIndex({'a.b.c': 1}, {name: "x"});
}
var res = t.update(query, {'$set': {"a.0.b.c": 0}}, false, true);
diff --git a/jstests/core/index_bounds_number_edge_cases.js b/jstests/core/index_bounds_number_edge_cases.js
index 3da4e53e2d0..0ab482028ed 100644
--- a/jstests/core/index_bounds_number_edge_cases.js
+++ b/jstests/core/index_bounds_number_edge_cases.js
@@ -6,7 +6,7 @@ t = db.indexboundsnumberedgecases;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: -Infinity});
t.save({a: -Number.MAX_VALUE});
diff --git a/jstests/core/index_check2.js b/jstests/core/index_check2.js
index 216ca7fb283..8feeb7d42a8 100644
--- a/jstests/core/index_check2.js
+++ b/jstests/core/index_check2.js
@@ -32,7 +32,7 @@ assert.eq(120, t.find(q1).itcount(), "q1 a");
assert.eq(120, t.find(q2).itcount(), "q2 a");
assert.eq(60, t.find(q3).itcount(), "q3 a");
-t.createIndex({tags: 1});
+t.ensureIndex({tags: 1});
assert.eq(120, t.find(q1).itcount(), "q1 a");
assert.eq(120, t.find(q2).itcount(), "q2 a");
diff --git a/jstests/core/index_check3.js b/jstests/core/index_check3.js
index da472ecb0c9..306b7415592 100644
--- a/jstests/core/index_check3.js
+++ b/jstests/core/index_check3.js
@@ -14,7 +14,7 @@ t.save({a: "z"});
assert.eq(1, t.find({a: {$lt: 2}}).itcount(), "A");
assert.eq(1, t.find({a: {$gt: 2}}).itcount(), "B");
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq(1, t.find({a: {$lt: 2}}).itcount(), "C");
assert.eq(1, t.find({a: {$gt: 2}}).itcount(), "D");
@@ -28,7 +28,7 @@ for (var i = 0; i < 100; i++) {
t.save(o);
}
-t.createIndex({foo: 1});
+t.ensureIndex({foo: 1});
var explain = t.find({foo: {$lt: 50}}).explain("executionStats");
assert.gt(30, explain.executionStats.totalKeysExamined, "lt");
@@ -41,7 +41,7 @@ for (var i = 0; i < 10; ++i) {
t.save({});
}
-t.createIndex({i: 1});
+t.ensureIndex({i: 1});
var explain = t.find({i: {$lte: 'a'}}).explain("executionStats");
assert.gt(3, explain.executionStats.totalKeysExamined, "lte");
diff --git a/jstests/core/index_check5.js b/jstests/core/index_check5.js
index 8921e014fcd..2a3e73f9e8d 100644
--- a/jstests/core/index_check5.js
+++ b/jstests/core/index_check5.js
@@ -14,5 +14,5 @@ t.save({
});
assert.eq(2, t.find({"scores.level": 2, "scores.score": {$gt: 30}}).itcount(), "A");
-t.createIndex({"scores.level": 1, "scores.score": 1});
+t.ensureIndex({"scores.level": 1, "scores.score": 1});
assert.eq(2, t.find({"scores.level": 2, "scores.score": {$gt: 30}}).itcount(), "B");
diff --git a/jstests/core/index_check6.js b/jstests/core/index_check6.js
index 646d64540cf..20310d2b0dd 100644
--- a/jstests/core/index_check6.js
+++ b/jstests/core/index_check6.js
@@ -12,7 +12,7 @@ function keysExamined(query, hint) {
return explain.executionStats.totalKeysExamined;
}
-t.createIndex({age: 1, rating: 1});
+t.ensureIndex({age: 1, rating: 1});
for (var age = 10; age < 50; age++) {
for (var rating = 0; rating < 10; rating++) {
@@ -98,7 +98,7 @@ for (var a = -1; a <= 1; a += 2) {
for (var c = -1; c <= 1; c += 2) {
t.dropIndexes();
var spec = {a: a, b: b, c: c};
- t.createIndex(spec);
+ t.ensureIndex(spec);
doTest(spec, spec);
doTest({a: -a, b: -b, c: -c}, spec);
}
diff --git a/jstests/core/index_check7.js b/jstests/core/index_check7.js
index 4a4ac2a0aa1..ae7ae7c9c71 100644
--- a/jstests/core/index_check7.js
+++ b/jstests/core/index_check7.js
@@ -9,10 +9,10 @@ t.drop();
for (var i = 0; i < 100; i++)
t.save({x: i});
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq(1, t.find({x: 27}).explain(true).executionStats.totalKeysExamined, "A");
-t.createIndex({x: -1});
+t.ensureIndex({x: -1});
assert.eq(1, t.find({x: 27}).explain(true).executionStats.totalKeysExamined, "B");
assert.eq(40, t.find({x: {$gt: 59}}).explain(true).executionStats.totalKeysExamined, "C");
diff --git a/jstests/core/index_diag.js b/jstests/core/index_diag.js
index 86f90c8d15c..b336e5cc141 100644
--- a/jstests/core/index_diag.js
+++ b/jstests/core/index_diag.js
@@ -49,7 +49,7 @@ if (FixtureHelpers.numberOfShardsForCollection(t) === 1) {
assert.commandWorked(t.createIndex({_id: 1, x: 1}));
assert.eq(all, t.find().hint({_id: 1, x: 1}).returnKey().toArray());
}
-assert.commandWorked(t.createIndex({_id: 1, x: 1}));
+assert.commandWorked(t.ensureIndex({_id: 1, x: 1}));
assert.eq(r(all), t.find().hint({_id: 1, x: 1}).sort({x: 1}).returnKey().toArray());
assert.eq([{}, {}, {}], t.find().hint({$natural: 1}).returnKey().toArray());
diff --git a/jstests/core/index_dropdups_ignore.js b/jstests/core/index_dropdups_ignore.js
index 0cc45d65648..aabea228c26 100644
--- a/jstests/core/index_dropdups_ignore.js
+++ b/jstests/core/index_dropdups_ignore.js
@@ -11,13 +11,13 @@ t.insert({_id: 1, a: 'dup'});
t.insert({_id: 2, a: 'dup'});
// Should fail with a dup-key error even though dropDups is true;
-var res = t.createIndex({a: 1}, {unique: true, dropDups: true});
+var res = t.ensureIndex({a: 1}, {unique: true, dropDups: true});
assert.commandFailed(res);
assert.eq(res.code, 11000, tojson(res));
// Succeeds with the dup manually removed.
t.remove({_id: 2});
-var res = t.createIndex({a: 1}, {unique: true, dropDups: true});
+var res = t.ensureIndex({a: 1}, {unique: true, dropDups: true});
assert.commandWorked(res);
// The spec should have been stripped of the dropDups option.
diff --git a/jstests/core/index_id_options.js b/jstests/core/index_id_options.js
index 475a1a6fe95..91bdce8090f 100644
--- a/jstests/core/index_id_options.js
+++ b/jstests/core/index_id_options.js
@@ -21,12 +21,12 @@ var coll = db.getSiblingDB("local").index_id_options;
// _id indexes must have key pattern {_id: 1}.
coll.drop();
assert.commandWorked(coll.runCommand("create", {autoIndexId: false}));
-assert.commandFailed(coll.createIndex({_id: -1}, {name: "_id_"}));
+assert.commandFailed(coll.ensureIndex({_id: -1}, {name: "_id_"}));
// The name of an _id index gets corrected to "_id_".
coll.drop();
assert.commandWorked(coll.runCommand("create", {autoIndexId: false}));
-assert.commandWorked(coll.createIndex({_id: 1}, {name: "bad"}));
+assert.commandWorked(coll.ensureIndex({_id: 1}, {name: "bad"}));
var spec = GetIndexHelpers.findByKeyPattern(coll.getIndexes(), {_id: 1});
assert.neq(null, spec, "_id index spec not found");
assert.eq("_id_", spec.name, tojson(spec));
@@ -34,35 +34,35 @@ assert.eq("_id_", spec.name, tojson(spec));
// _id indexes cannot have any options other than "key", "name", "ns", "v", and "collation."
coll.drop();
assert.commandWorked(coll.runCommand("create", {autoIndexId: false}));
-assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", unique: true}));
-assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", sparse: false}));
-assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", partialFilterExpression: {a: 1}}));
-assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", expireAfterSeconds: 3600}));
-assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", background: false}));
-assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", unknown: true}));
-assert.commandWorked(coll.createIndex(
+assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", unique: true}));
+assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", sparse: false}));
+assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", partialFilterExpression: {a: 1}}));
+assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", expireAfterSeconds: 3600}));
+assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", background: false}));
+assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", unknown: true}));
+assert.commandWorked(coll.ensureIndex(
{_id: 1}, {name: "_id_", ns: coll.getFullName(), v: 2, collation: {locale: "simple"}}));
// _id indexes must have the collection default collation.
coll.drop();
assert.commandWorked(coll.runCommand("create", {autoIndexId: false}));
-assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", collation: {locale: "en_US"}}));
-assert.commandWorked(coll.createIndex({_id: 1}, {name: "_id_", collation: {locale: "simple"}}));
+assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", collation: {locale: "en_US"}}));
+assert.commandWorked(coll.ensureIndex({_id: 1}, {name: "_id_", collation: {locale: "simple"}}));
coll.drop();
assert.commandWorked(coll.runCommand("create", {autoIndexId: false}));
-assert.commandWorked(coll.createIndex({_id: 1}, {name: "_id_"}));
+assert.commandWorked(coll.ensureIndex({_id: 1}, {name: "_id_"}));
coll.drop();
assert.commandWorked(coll.runCommand("create", {autoIndexId: false, collation: {locale: "en_US"}}));
-assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", collation: {locale: "simple"}}));
-assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", collation: {locale: "fr_CA"}}));
+assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", collation: {locale: "simple"}}));
+assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", collation: {locale: "fr_CA"}}));
assert.commandWorked(
- coll.createIndex({_id: 1}, {name: "_id_", collation: {locale: "en_US", strength: 3}}));
+ coll.ensureIndex({_id: 1}, {name: "_id_", collation: {locale: "en_US", strength: 3}}));
coll.drop();
assert.commandWorked(coll.runCommand("create", {autoIndexId: false, collation: {locale: "en_US"}}));
-assert.commandWorked(coll.createIndex({_id: 1}, {name: "_id_"}));
+assert.commandWorked(coll.ensureIndex({_id: 1}, {name: "_id_"}));
spec = GetIndexHelpers.findByName(coll.getIndexes(), "_id_");
assert.neq(null, spec, "_id index spec not found");
assert.eq("en_US", spec.collation.locale, tojson(spec));
@@ -70,6 +70,6 @@ assert.eq("en_US", spec.collation.locale, tojson(spec));
// Non-_id indexes cannot have the name "_id_".
coll.drop();
assert.commandWorked(coll.runCommand("create", {autoIndexId: false}));
-assert.commandFailed(coll.createIndex({_id: "hashed"}, {name: "_id_"}));
-assert.commandFailed(coll.createIndex({a: 1}, {name: "_id_"}));
+assert.commandFailed(coll.ensureIndex({_id: "hashed"}, {name: "_id_"}));
+assert.commandFailed(coll.ensureIndex({a: 1}, {name: "_id_"}));
})();
diff --git a/jstests/core/index_many.js b/jstests/core/index_many.js
index cdd559c9be5..f95d4ac50de 100644
--- a/jstests/core/index_many.js
+++ b/jstests/core/index_many.js
@@ -22,7 +22,7 @@ function f() {
patt = {x: 1};
if (x == 64)
patt = {y: 1};
- lastErr = t.createIndex(patt);
+ lastErr = t.ensureIndex(patt);
x++;
}
diff --git a/jstests/core/index_many2.js b/jstests/core/index_many2.js
index 70fada7396e..f6f6b0cb392 100644
--- a/jstests/core/index_many2.js
+++ b/jstests/core/index_many2.js
@@ -16,7 +16,7 @@ function make(n) {
}
for (i = 1; i < 1000; i++) {
- t.createIndex(make(i));
+ t.ensureIndex(make(i));
}
assert.eq(64, t.getIndexKeys().length, "A2");
@@ -26,7 +26,7 @@ num = t.getIndexKeys().length;
t.dropIndex(make(num - 1));
assert.eq(num - 1, t.getIndexKeys().length, "B0");
-t.createIndex({z: 1});
+t.ensureIndex({z: 1});
assert.eq(num, t.getIndexKeys().length, "B1");
t.dropIndexes("*");
diff --git a/jstests/core/index_partial_validate.js b/jstests/core/index_partial_validate.js
index 5011b4b8bc2..2319aac2954 100644
--- a/jstests/core/index_partial_validate.js
+++ b/jstests/core/index_partial_validate.js
@@ -6,10 +6,10 @@
var t = db.index_partial_validate;
t.drop();
-var res = t.createIndex({a: 1}, {partialFilterExpression: {a: {$lte: 1}}});
+var res = t.ensureIndex({a: 1}, {partialFilterExpression: {a: {$lte: 1}}});
assert.commandWorked(res);
-res = t.createIndex({b: 1});
+res = t.ensureIndex({b: 1});
assert.commandWorked(res);
res = t.insert({non_indexed_field: 'x'});
diff --git a/jstests/core/index_partial_write_ops.js b/jstests/core/index_partial_write_ops.js
index 6adcb8933fd..df80ac33b42 100644
--- a/jstests/core/index_partial_write_ops.js
+++ b/jstests/core/index_partial_write_ops.js
@@ -21,7 +21,7 @@ var getNumKeys = function(idxName) {
coll.drop();
// Create partial index.
-assert.commandWorked(coll.createIndex({x: 1}, {unique: true, partialFilterExpression: {a: 1}}));
+assert.commandWorked(coll.ensureIndex({x: 1}, {unique: true, partialFilterExpression: {a: 1}}));
assert.commandWorked(coll.insert({_id: 1, x: 5, a: 2, b: 1})); // Not in index.
assert.commandWorked(coll.insert({_id: 2, x: 6, a: 1, b: 1})); // In index.
diff --git a/jstests/core/index_sparse1.js b/jstests/core/index_sparse1.js
index 58bc5baa9b8..a7c1e8605ef 100644
--- a/jstests/core/index_sparse1.js
+++ b/jstests/core/index_sparse1.js
@@ -14,13 +14,13 @@ t.insert({_id: 5});
assert.eq(5, t.count(), "A1");
assert.eq(5, t.find().sort({x: 1}).itcount(), "A2");
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq(2, t.getIndexes().length, "B1");
assert.eq(5, t.find().sort({x: 1}).itcount(), "B2");
t.dropIndex({x: 1});
assert.eq(1, t.getIndexes().length, "B3");
-t.createIndex({x: 1}, {sparse: 1});
+t.ensureIndex({x: 1}, {sparse: 1});
assert.eq(2, t.getIndexes().length, "C1");
assert.eq(5, t.find().sort({x: 1}).itcount(), "C2");
t.dropIndex({x: 1});
@@ -31,14 +31,14 @@ assert.eq(1, t.getIndexes().length, "C3");
t.remove({_id: 2});
// test that we can't create a unique index without sparse
-assert.commandFailed(t.createIndex({x: 1}, {unique: 1}));
+assert.commandFailed(t.ensureIndex({x: 1}, {unique: 1}));
assert.eq(1, t.getIndexes().length, "D2");
-t.createIndex({x: 1}, {unique: 1, sparse: 1});
+t.ensureIndex({x: 1}, {unique: 1, sparse: 1});
assert.eq(2, t.getIndexes().length, "E1");
t.dropIndex({x: 1});
assert.eq(1, t.getIndexes().length, "E3");
t.insert({_id: 2, x: 2});
-t.createIndex({x: 1}, {unique: 1, sparse: 1});
+t.ensureIndex({x: 1}, {unique: 1, sparse: 1});
assert.eq(1, t.getIndexes().length, "F1");
diff --git a/jstests/core/index_sparse2.js b/jstests/core/index_sparse2.js
index 324b46d8216..148ad70b203 100644
--- a/jstests/core/index_sparse2.js
+++ b/jstests/core/index_sparse2.js
@@ -9,14 +9,14 @@ t.insert({_id: 1, x: 1, y: 1});
t.insert({_id: 2, x: 2});
t.insert({_id: 3});
-t.createIndex({x: 1, y: 1});
+t.ensureIndex({x: 1, y: 1});
assert.eq(2, t.getIndexes().length, "A1");
assert.eq(3, t.find().sort({x: 1, y: 1}).count(), "A2 count()");
assert.eq(3, t.find().sort({x: 1, y: 1}).itcount(), "A2 itcount()");
t.dropIndex({x: 1, y: 1});
assert.eq(1, t.getIndexes().length, "A3");
-t.createIndex({x: 1, y: 1}, {sparse: 1});
+t.ensureIndex({x: 1, y: 1}, {sparse: 1});
assert.eq(2, t.getIndexes().length, "B1");
assert.eq(3, t.find().sort({x: 1, y: 1}).count(), "B2 count()");
assert.eq(3, t.find().sort({x: 1, y: 1}).itcount(), "B2 itcount()");
diff --git a/jstests/core/index_type_change.js b/jstests/core/index_type_change.js
index d23984a132d..4ecb5081347 100644
--- a/jstests/core/index_type_change.js
+++ b/jstests/core/index_type_change.js
@@ -18,7 +18,7 @@ load("jstests/libs/analyze_plan.js"); // For 'isIndexOnly'.
var coll = db.index_type_change;
coll.drop();
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
assert.commandWorked(coll.insert({a: 2}));
assert.eq(1, coll.find({a: {$type: "double"}}).itcount());
diff --git a/jstests/core/indexa.js b/jstests/core/indexa.js
index 01fde035621..90e74adc4f4 100644
--- a/jstests/core/indexa.js
+++ b/jstests/core/indexa.js
@@ -8,7 +8,7 @@
t = db.indexa;
t.drop();
-t.createIndex({x: 1}, true);
+t.ensureIndex({x: 1}, true);
t.insert({'x': 'A'});
t.insert({'x': 'B'});
diff --git a/jstests/core/indexapi.js b/jstests/core/indexapi.js
index 29d39ea721b..14cf634e556 100644
--- a/jstests/core/indexapi.js
+++ b/jstests/core/indexapi.js
@@ -31,14 +31,14 @@ c.dropDups = true;
assert.eq(c, t._indexSpec({x: 1}, [true, true]), "G");
assert.eq(c, t._indexSpec({x: 1}, {unique: true, dropDups: true}), "F");
-t.createIndex({x: 1}, {unique: true});
+t.ensureIndex({x: 1}, {unique: true});
idx = t.getIndexes();
assert.eq(2, idx.length, "M1");
assert.eq(key, idx[1].key, "M2");
assert(idx[1].unique, "M3");
t.drop();
-t.createIndex({x: 1}, {unique: 1});
+t.ensureIndex({x: 1}, {unique: 1});
idx = t.getIndexes();
assert.eq(2, idx.length, "M1");
assert.eq(key, idx[1].key, "M2");
diff --git a/jstests/core/indexb.js b/jstests/core/indexb.js
index 59546f7fae2..6890dda3cbc 100644
--- a/jstests/core/indexb.js
+++ b/jstests/core/indexb.js
@@ -10,7 +10,7 @@
t = db.indexb;
t.drop();
-t.createIndex({a: 1}, true);
+t.ensureIndex({a: 1}, true);
t.insert({a: 1});
diff --git a/jstests/core/indexc.js b/jstests/core/indexc.js
index bf5735380fa..3bc4c9eaca8 100644
--- a/jstests/core/indexc.js
+++ b/jstests/core/indexc.js
@@ -13,8 +13,8 @@ for (var i = 1; i < 100; i++) {
assert.eq(50, t.find({ts: {$lt: mid}}).itcount(), "A");
assert.eq(50, t.find({ts: {$lt: mid}}).sort({ts: 1}).itcount(), "B");
-t.createIndex({ts: 1, cats: 1});
-t.createIndex({cats: 1});
+t.ensureIndex({ts: 1, cats: 1});
+t.ensureIndex({cats: 1});
// multi-key bug was firing here (related to getsetdup()):
assert.eq(50, t.find({ts: {$lt: mid}}).itcount(), "C");
diff --git a/jstests/core/indexe.js b/jstests/core/indexe.js
index a307882adc3..6961229c682 100644
--- a/jstests/core/indexe.js
+++ b/jstests/core/indexe.js
@@ -13,7 +13,7 @@ assert.eq(num, t.find().count(), "A1");
assert.eq(num, t.find({a: "b"}).count(), "B1");
assert.eq(num, t.find({a: "b"}).itcount(), "C1");
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq(num, t.find().count(), "A2");
assert.eq(num, t.find().sort({a: 1}).count(), "A2a");
diff --git a/jstests/core/indexf.js b/jstests/core/indexf.js
index 4dc8fb0b060..cbe1b968b5e 100644
--- a/jstests/core/indexf.js
+++ b/jstests/core/indexf.js
@@ -7,7 +7,7 @@
t = db.indexf;
t.drop();
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
t.save({x: 2});
t.save({y: 3});
diff --git a/jstests/core/indexg.js b/jstests/core/indexg.js
index 486f4be0ebe..3cafede4cff 100644
--- a/jstests/core/indexg.js
+++ b/jstests/core/indexg.js
@@ -9,5 +9,5 @@ doit = function() {
assert.eq(1, f.count({list: {$in: [1], $not: {$in: [3]}}}));
};
doit();
-f.createIndex({list: 1});
+f.ensureIndex({list: 1});
doit(); \ No newline at end of file
diff --git a/jstests/core/indexj.js b/jstests/core/indexj.js
index 64cf9844d7f..76bf8cb17e9 100644
--- a/jstests/core/indexj.js
+++ b/jstests/core/indexj.js
@@ -20,12 +20,12 @@ function keysExamined(query, hint, sort) {
return explain.executionStats.totalKeysExamined;
}
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: 5});
assert.eq(0, keysExamined({a: {$gt: 4, $lt: 5}}), "A");
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: 4});
assert.eq(0, keysExamined({a: {$gt: 4, $lt: 5}}), "B");
@@ -39,7 +39,7 @@ t.save({a: 5});
assert.eq(0, keysExamined({a: {$gt: 4, $lt: 5}}), "D");
t.drop();
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
t.save({a: 1, b: 1});
t.save({a: 1, b: 2});
t.save({a: 2, b: 1});
diff --git a/jstests/core/indexl.js b/jstests/core/indexl.js
index cde169eda71..c83638607d4 100644
--- a/jstests/core/indexl.js
+++ b/jstests/core/indexl.js
@@ -23,5 +23,5 @@ function test(t) {
t.drop();
test(t);
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
test(t); \ No newline at end of file
diff --git a/jstests/core/indexm.js b/jstests/core/indexm.js
index 7613b125357..820bedd7baa 100644
--- a/jstests/core/indexm.js
+++ b/jstests/core/indexm.js
@@ -13,12 +13,12 @@ function test() {
test();
// Now create an index.
-t.createIndex({"a": 1});
+t.ensureIndex({"a": 1});
test();
// Now create a different index.
t.dropIndexes();
-t.createIndex({"a.x": 1});
+t.ensureIndex({"a.x": 1});
test();
// Drop the indexes.
diff --git a/jstests/core/indexn.js b/jstests/core/indexn.js
index 02547280ad9..014ba050cbc 100644
--- a/jstests/core/indexn.js
+++ b/jstests/core/indexn.js
@@ -9,8 +9,8 @@ t.drop();
t.save({a: 1, b: [1, 2]});
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
// {a:1} is a single key index, so no matches are possible for this query
assert.eq(0, t.count({a: {$gt: 5, $lt: 0}}));
diff --git a/jstests/core/indexp.js b/jstests/core/indexp.js
index 8199e0f132c..71e9f8eadb9 100644
--- a/jstests/core/indexp.js
+++ b/jstests/core/indexp.js
@@ -6,18 +6,18 @@
var coll = db.jstests_indexp;
// Empty field checks.
-assert.commandFailed(coll.createIndex({'a..b': 1}));
-assert.commandFailed(coll.createIndex({'.a': 1}));
-assert.commandFailed(coll.createIndex({'a.': 1}));
-assert.commandFailed(coll.createIndex({'.': 1}));
-assert.commandFailed(coll.createIndex({'': 1}));
-assert.commandWorked(coll.createIndex({'a.b': 1}));
+assert.commandFailed(coll.ensureIndex({'a..b': 1}));
+assert.commandFailed(coll.ensureIndex({'.a': 1}));
+assert.commandFailed(coll.ensureIndex({'a.': 1}));
+assert.commandFailed(coll.ensureIndex({'.': 1}));
+assert.commandFailed(coll.ensureIndex({'': 1}));
+assert.commandWorked(coll.ensureIndex({'a.b': 1}));
// '$'-prefixed field checks.
-assert.commandFailed(coll.createIndex({'$a': 1}));
-assert.commandFailed(coll.createIndex({'a.$b': 1}));
-assert.commandFailed(coll.createIndex({'$db': 1}));
-assert.commandWorked(coll.createIndex({'a$ap': 1})); // $ in middle is ok
-assert.commandWorked(coll.createIndex({'a.$id': 1})); // $id/$db/$ref are execptions
+assert.commandFailed(coll.ensureIndex({'$a': 1}));
+assert.commandFailed(coll.ensureIndex({'a.$b': 1}));
+assert.commandFailed(coll.ensureIndex({'$db': 1}));
+assert.commandWorked(coll.ensureIndex({'a$ap': 1})); // $ in middle is ok
+assert.commandWorked(coll.ensureIndex({'a.$id': 1})); // $id/$db/$ref are execptions
coll.dropIndexes();
diff --git a/jstests/core/indexr.js b/jstests/core/indexr.js
index de3afe8cdc1..15cd56e9681 100644
--- a/jstests/core/indexr.js
+++ b/jstests/core/indexr.js
@@ -15,8 +15,8 @@ assert.eq(1, t.count({a: {b: 3, c: 6}, 'a.c': {$lt: 4}}));
// Check with single key indexes.
t.remove({});
-t.createIndex({'a.b': 1, 'a.c': 1});
-t.createIndex({a: 1, 'a.c': 1});
+t.ensureIndex({'a.b': 1, 'a.c': 1});
+t.ensureIndex({a: 1, 'a.c': 1});
assert.eq(0, t.count({'a.b': {$gt: 2}, 'a.c': {$lt: 4}}));
assert.eq(0, t.count({a: {b: 3, c: 6}, 'a.c': {$lt: 4}}));
diff --git a/jstests/core/indexs.js b/jstests/core/indexs.js
index 6ee625071e2..2fc9724a590 100644
--- a/jstests/core/indexs.js
+++ b/jstests/core/indexs.js
@@ -4,16 +4,16 @@
t = db.jstests_indexs;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: [{b: 3}]});
assert.eq(1, t.count({a: {b: 3}}));
t.drop();
-t.createIndex({a: 1, 'a.b': 1});
+t.ensureIndex({a: 1, 'a.b': 1});
t.save({a: {b: 3}});
assert.eq(1, t.count({a: {b: 3}}));
t.drop();
-t.createIndex({a: 1, 'a.b': 1});
+t.ensureIndex({a: 1, 'a.b': 1});
t.save({a: [{b: 3}]});
assert.eq(1, t.count({a: {b: 3}}));
diff --git a/jstests/core/indext.js b/jstests/core/indext.js
index 1ac92d6be5d..163a3e4a8a3 100644
--- a/jstests/core/indext.js
+++ b/jstests/core/indext.js
@@ -3,12 +3,12 @@
t = db.jstests_indext;
t.drop();
-t.createIndex({'a.b': 1}, {sparse: true});
+t.ensureIndex({'a.b': 1}, {sparse: true});
t.save({a: []});
t.save({a: 1});
assert.eq(0, t.find().hint({'a.b': 1}).itcount());
-t.createIndex({'a.b': 1, 'a.c': 1}, {sparse: true});
+t.ensureIndex({'a.b': 1, 'a.c': 1}, {sparse: true});
t.save({a: []});
t.save({a: 1});
assert.eq(0, t.find().hint({'a.b': 1, 'a.c': 1}).itcount());
diff --git a/jstests/core/indexu.js b/jstests/core/indexu.js
index 973fc0e4985..22af42d5d6a 100644
--- a/jstests/core/indexu.js
+++ b/jstests/core/indexu.js
@@ -15,56 +15,56 @@ var noDupDoc = {a: [{'1': 1}]};
// Test that we can't index dupDoc.
assert.commandWorked(t.save(dupDoc));
-assert.commandFailedWithCode(t.createIndex({'a.0': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.0': 1}), 16746);
// Test that we can fail gracefully when dupDoc has a large array padded with nulls.
// Index is based on max padding constant in mongo/db/update/path_support.h
assert.commandWorked(t.update({_id: 0}, {$set: {'a.1500001': 1}}));
-assert.commandFailedWithCode(t.createIndex({'a.0': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.0': 1}), 16746);
t.remove({});
-assert.commandWorked(t.createIndex({'a.0': 1}));
+assert.commandWorked(t.ensureIndex({'a.0': 1}));
assert.writeError(t.save(dupDoc));
// Test that we can't index dupDoc2.
t.drop();
assert.commandWorked(t.save(dupDoc2));
-assert.commandFailedWithCode(t.createIndex({'a.1': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.1': 1}), 16746);
t.remove({});
-assert.commandWorked(t.createIndex({'a.1': 1}));
+assert.commandWorked(t.ensureIndex({'a.1': 1}));
assert.writeError(t.save(dupDoc2));
// Test that we can index dupDoc with a different index.
t.drop();
-t.createIndex({'a.b': 1});
+t.ensureIndex({'a.b': 1});
assert.commandWorked(t.save(dupDoc));
// Test number field starting with hyphen.
t.drop();
-t.createIndex({'a.-1': 1});
+t.ensureIndex({'a.-1': 1});
assert.commandWorked(t.save({a: [{'-1': 1}]}));
// Test number field starting with zero.
t.drop();
-t.createIndex({'a.00': 1});
+t.ensureIndex({'a.00': 1});
assert.commandWorked(t.save({a: [{'00': 1}]}));
// Test multiple array indexes
t.drop();
-t.createIndex({'a.0': 1, 'a.1': 1});
+t.ensureIndex({'a.0': 1, 'a.1': 1});
assert.commandWorked(t.save({a: [{'1': 1}]}));
assert.writeError(t.save({a: [{'1': 1}, 4]}));
// Test that we can index noDupDoc.
t.drop();
t.save(noDupDoc);
-assert.commandWorked(t.createIndex({'a.0': 1}));
-assert.commandWorked(t.createIndex({'a.1': 1}));
+assert.commandWorked(t.ensureIndex({'a.0': 1}));
+assert.commandWorked(t.ensureIndex({'a.1': 1}));
t.drop();
-t.createIndex({'a.0': 1});
-t.createIndex({'a.1': 1});
+t.ensureIndex({'a.0': 1});
+t.ensureIndex({'a.1': 1});
assert.commandWorked(t.save(noDupDoc));
// Test that we can query noDupDoc.
@@ -76,7 +76,7 @@ assert.eq(1, t.find({'a.0': {'1': 1}}).hint({$natural: 1}).itcount());
// Check multiple nested array fields.
t.drop();
t.save({a: [[1]]});
-assert.commandWorked(t.createIndex({'a.0.0': 1}));
+assert.commandWorked(t.ensureIndex({'a.0.0': 1}));
assert.eq(1, t.find({'a.0.0': 1}).hint({$natural: 1}).itcount());
assert.eq(1, t.find({'a.0.0': 1}).hint({'a.0.0': 1}).itcount());
@@ -84,36 +84,36 @@ assert.eq(1, t.find({'a.0.0': 1}).hint({'a.0.0': 1}).itcount());
// field.
t.drop();
t.save({a: [[1], {'0': 1}]});
-assert.commandFailed(t.createIndex({'a.0.0': 1}));
+assert.commandFailed(t.ensureIndex({'a.0.0': 1}));
// Check where there is a duplicate for a fully addressed field.
t.drop();
assert.commandWorked(t.save({a: [[1], {'0': [1]}]}));
-assert.commandFailedWithCode(t.createIndex({'a.0.0': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.0.0': 1}), 16746);
// Two ways of addressing parse to an array.
t.drop();
t.save({a: [{'0': 1}]});
-assert.commandFailedWithCode(t.createIndex({'a.0.0': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.0.0': 1}), 16746);
// Test several key depths - with same arrays being found.
t.drop();
t.save({a: [{'0': [{'0': 1}]}]});
-assert.commandFailedWithCode(t.createIndex({'a.0.0.0.0.0.0': 1}), 16746);
-assert.commandFailedWithCode(t.createIndex({'a.0.0.0.0.0': 1}), 16746);
-assert.commandFailedWithCode(t.createIndex({'a.0.0.0.0': 1}), 16746);
-assert.commandFailedWithCode(t.createIndex({'a.0.0.0': 1}), 16746);
-assert.commandFailedWithCode(t.createIndex({'a.0.0': 1}), 16746);
-assert.commandFailedWithCode(t.createIndex({'a.0': 1}), 16746);
-assert.commandWorked(t.createIndex({'a': 1}));
+assert.commandFailedWithCode(t.ensureIndex({'a.0.0.0.0.0.0': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.0.0.0.0.0': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.0.0.0.0': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.0.0.0': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.0.0': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.0': 1}), 16746);
+assert.commandWorked(t.ensureIndex({'a': 1}));
// Two prefixes extract docs, but one terminates extraction before array.
t.drop();
t.save({a: [{'0': {'c': []}}]});
-assert.commandFailedWithCode(t.createIndex({'a.0.c': 1}), 16746);
+assert.commandFailedWithCode(t.ensureIndex({'a.0.c': 1}), 16746);
t.drop();
t.save({a: [[{'b': 1}]]});
assert.eq(1, t.find({'a.0.b': 1}).itcount());
-t.createIndex({'a.0.b': 1});
+t.ensureIndex({'a.0.b': 1});
assert.eq(1, t.find({'a.0.b': 1}).itcount());
diff --git a/jstests/core/insert_illegal_doc.js b/jstests/core/insert_illegal_doc.js
index f6344f1c62b..64ecb0ae7ad 100644
--- a/jstests/core/insert_illegal_doc.js
+++ b/jstests/core/insert_illegal_doc.js
@@ -2,7 +2,7 @@
// "parallel indexing of arrays" test
var coll = db.insert_illegal_doc;
coll.drop();
-coll.createIndex({a: 1, b: 1});
+coll.ensureIndex({a: 1, b: 1});
var res;
// test upsert
diff --git a/jstests/core/js3.js b/jstests/core/js3.js
index 8698195d6c4..89847210714 100644
--- a/jstests/core/js3.js
+++ b/jstests/core/js3.js
@@ -18,8 +18,8 @@ for (z = 0; z < 2; z++) {
t.drop();
if (z > 0) {
- t.createIndex({_id: 1});
- t.createIndex({i: 1});
+ t.ensureIndex({_id: 1});
+ t.ensureIndex({i: 1});
}
for (i = 0; i < 1000; i++)
@@ -51,8 +51,8 @@ for (z = 0; z < 2; z++) {
debug(ok);
assert(ok);
- t.createIndex({z: 1});
- t.createIndex({q: 1});
+ t.ensureIndex({z: 1});
+ t.ensureIndex({q: 1});
debug("before indexed find");
diff --git a/jstests/core/list_indexes.js b/jstests/core/list_indexes.js
index a81a1adf68a..040d30e6290 100644
--- a/jstests/core/list_indexes.js
+++ b/jstests/core/list_indexes.js
@@ -59,7 +59,7 @@ assert.eq(["_id_"], cursorGetIndexNames(getListIndexesCursor(coll)));
coll.drop();
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
-assert.commandWorked(coll.createIndex({a: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {unique: true}));
specs = cursorGetIndexSpecs(getListIndexesCursor(coll));
assert.eq(2, specs.length);
assert.eq("_id_", specs[0].name);
@@ -84,7 +84,7 @@ assert.commandFailed(coll.getDB().runCommand({listIndexes: []}));
coll.drop();
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
-assert.commandWorked(coll.createIndex({a: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {unique: true}));
cursor = getListIndexesCursor(coll, {cursor: {batchSize: 2}});
assert.eq(2, cursor.objsLeftInBatch());
@@ -124,9 +124,9 @@ assert.eq(["_id_", "a_1"], cursorGetIndexNames(cursor));
coll.drop();
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
-assert.commandWorked(coll.createIndex({a: 1}, {unique: true}));
-assert.commandWorked(coll.createIndex({b: 1}, {unique: true}));
-assert.commandWorked(coll.createIndex({c: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({b: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({c: 1}, {unique: true}));
cursor = getListIndexesCursor(coll, {cursor: {batchSize: 0}}, 2);
assert.eq(0, cursor.objsLeftInBatch());
@@ -167,9 +167,9 @@ if (!FixtureHelpers.isMongos(db)) {
coll.drop();
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
-assert.commandWorked(coll.createIndex({a: 1}, {unique: true}));
-assert.commandWorked(coll.createIndex({b: 1}, {unique: true}));
-assert.commandWorked(coll.createIndex({c: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({b: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({c: 1}, {unique: true}));
res = coll.runCommand("listIndexes", {cursor: {batchSize: 0}});
cursor = new DBCommandCursor(coll.getDB(), res, 2);
diff --git a/jstests/core/list_indexes_invalid.js b/jstests/core/list_indexes_invalid.js
index 7b73a4278ce..43d64a594c2 100644
--- a/jstests/core/list_indexes_invalid.js
+++ b/jstests/core/list_indexes_invalid.js
@@ -8,7 +8,7 @@ var coll = db.list_indexes_invalid;
coll.drop();
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
-assert.commandWorked(coll.createIndex({a: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({a: 1}, {unique: true}));
assert.throws(function() {
getListIndexesCursor(coll, {cursor: 0});
diff --git a/jstests/core/minmax.js b/jstests/core/minmax.js
index b4f181689a2..14f4ed0ec2c 100644
--- a/jstests/core/minmax.js
+++ b/jstests/core/minmax.js
@@ -16,7 +16,7 @@ function addData() {
assert.commandWorked(coll.save({a: 2, b: 2}));
}
-assert.commandWorked(coll.createIndex({a: 1, b: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: 1}));
addData();
assert.eq(1, coll.find().hint({a: 1, b: 1}).min({a: 1, b: 2}).max({a: 2, b: 1}).toArray().length);
@@ -31,7 +31,7 @@ assert.eq(3,
coll.find().hint({a: 1, b: 1}).max({a: 2, b: 1.5}).hint({a: 1, b: 1}).toArray().length);
coll.drop();
-assert.commandWorked(coll.createIndex({a: 1, b: -1}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: -1}));
addData();
assert.eq(4, coll.find().hint({a: 1, b: -1}).min({a: 1, b: 2}).toArray().length);
assert.eq(4, coll.find().hint({a: 1, b: -1}).max({a: 2, b: 0.5}).toArray().length);
@@ -78,7 +78,7 @@ error = assert.throws(function() {
assert.eq(error.code, ErrorCodes.NoQueryExecutionPlans);
coll.drop();
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
for (let i = 0; i < 10; ++i) {
assert.commandWorked(coll.save({_id: i, a: i}));
}
@@ -103,7 +103,7 @@ assert.eq(error.code, 51175);
coll.drop();
addData();
-assert.commandWorked(coll.createIndex({a: 1, b: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: 1}));
error = assert.throws(function() {
coll.find().min({a: 1, b: 2}).max({a: 1, b: 2}).hint({a: 1, b: 1}).toArray();
@@ -112,7 +112,7 @@ assert.eq(error.code, 51175);
// Test ascending index.
coll.drop();
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
assert.commandWorked(coll.insert({a: 3}));
assert.commandWorked(coll.insert({a: 4}));
assert.commandWorked(coll.insert({a: 5}));
@@ -134,7 +134,7 @@ assert(!cursor.hasNext());
// Test descending index.
assert.commandWorked(coll.dropIndexes());
-assert.commandWorked(coll.createIndex({a: -1}));
+assert.commandWorked(coll.ensureIndex({a: -1}));
cursor = coll.find().hint({a: -1}).min({a: 4});
if (FixtureHelpers.numberOfShardsForCollection(coll) === 1) {
diff --git a/jstests/core/mr_multikey_deduping.js b/jstests/core/mr_multikey_deduping.js
index e3f729ef16f..604635a67fc 100644
--- a/jstests/core/mr_multikey_deduping.js
+++ b/jstests/core/mr_multikey_deduping.js
@@ -39,7 +39,7 @@ outColl.drop();
assert(outColl.drop());
// Now test that we get the same results when there's an index present.
- assert.commandWorked(coll.createIndex({arr: 1}));
+ assert.commandWorked(coll.ensureIndex({arr: 1}));
res = assert.commandWorked(coll.mapReduce(
mapFn, reduceFn, {out: {merge: outColl.getName()}, query: {arr: {$gte: 0}}}));
assert(outColl.drop());
@@ -93,7 +93,7 @@ outColl.drop();
resultsEq([{_id: "cat", value: 1}, {_id: "dog", value: 1}], resultsNoIndexEqualityOnName));
assert(resultsEq(resultsNoIndexNoQuery, resultsNoIndexRangeOnName));
- assert.commandWorked(coll.createIndex({name: 1, tags: 1}));
+ assert.commandWorked(coll.ensureIndex({name: 1, tags: 1}));
const resultsIndexedNoQuery =
assert
diff --git a/jstests/core/mr_sort.js b/jstests/core/mr_sort.js
index c1ce7d3861b..df98e6a6d3d 100644
--- a/jstests/core/mr_sort.js
+++ b/jstests/core/mr_sort.js
@@ -12,7 +12,7 @@
t = db.mr_sort;
t.drop();
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
t.insert({x: 1});
t.insert({x: 10});
diff --git a/jstests/core/multi.js b/jstests/core/multi.js
index ac961ed7a9c..c7853b18f25 100644
--- a/jstests/core/multi.js
+++ b/jstests/core/multi.js
@@ -1,7 +1,7 @@
t = db.jstests_multi;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: [1, 2]});
assert.eq(1, t.find({a: {$gt: 0}}).count(), "A");
assert.eq(1, t.find({a: {$gt: 0}}).toArray().length, "B");
diff --git a/jstests/core/multi2.js b/jstests/core/multi2.js
index 64473e4de98..8c1c4ea5f3c 100644
--- a/jstests/core/multi2.js
+++ b/jstests/core/multi2.js
@@ -10,13 +10,13 @@ t.save({});
assert.eq(3, t.find({x: 1}).count(), "A");
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq(3, t.find({x: 1}).count(), "B");
assert.eq(4, t.find().sort({x: 1, a: 1}).count(), "s1");
assert.eq(1, t.find({x: 1, a: null}).count(), "B2");
t.dropIndex({x: 1});
-t.createIndex({x: 1, a: 1});
+t.ensureIndex({x: 1, a: 1});
assert.eq(3, t.find({x: 1}).count(), "C"); // SERVER-279
assert.eq(4, t.find().sort({x: 1, a: 1}).count(), "s2");
assert.eq(1, t.find({x: 1, a: null}).count(), "C2");
diff --git a/jstests/core/multikey_geonear.js b/jstests/core/multikey_geonear.js
index 4b1cd5eb482..ad24afb0c98 100644
--- a/jstests/core/multikey_geonear.js
+++ b/jstests/core/multikey_geonear.js
@@ -16,7 +16,7 @@ function checkResults(cursor) {
assert(!cursor.hasNext());
}
-t.createIndex({a: 1, b: "2dsphere"});
+t.ensureIndex({a: 1, b: "2dsphere"});
t.insert({_id: 0, a: 0, b: {type: "Point", coordinates: [0, 0]}});
t.insert({_id: 1, a: 0, b: {type: "Point", coordinates: [1, 1]}});
@@ -33,7 +33,7 @@ checkResults(cursor);
// Repeat these tests for a 2d index.
t.drop();
-t.createIndex({a: "2d", b: 1});
+t.ensureIndex({a: "2d", b: 1});
t.insert({_id: 0, a: [0, 0], b: 0});
t.insert({_id: 1, a: [1, 1], b: 1});
t.insert({_id: 2, a: [2, 2], b: 2});
@@ -47,7 +47,7 @@ checkResults(cursor);
// The fields in the compound 2dsphere index share a prefix.
t.drop();
-t.createIndex({"a.b": 1, "a.c": "2dsphere"});
+t.ensureIndex({"a.b": 1, "a.c": "2dsphere"});
t.insert({_id: 0, a: [{b: 0}, {c: {type: "Point", coordinates: [0, 0]}}]});
t.insert({_id: 1, a: [{b: 1}, {c: {type: "Point", coordinates: [1, 1]}}]});
t.insert({_id: 2, a: [{b: 2}, {c: {type: "Point", coordinates: [2, 2]}}]});
@@ -66,7 +66,7 @@ assert(!cursor.hasNext());
// The fields in the compound 2d index share a prefix.
t.drop();
-t.createIndex({"a.b": "2d", "a.c": 1});
+t.ensureIndex({"a.b": "2d", "a.c": 1});
t.insert({_id: 0, a: [{b: [0, 0]}, {c: 0}]});
t.insert({_id: 1, a: [{b: [1, 1]}, {c: 1}]});
t.insert({_id: 2, a: [{b: [2, 2]}, {c: 2}]});
diff --git a/jstests/core/ne1.js b/jstests/core/ne1.js
index 5069637eb30..2128bd3a936 100644
--- a/jstests/core/ne1.js
+++ b/jstests/core/ne1.js
@@ -6,5 +6,5 @@ t.save({x: 2});
t.save({x: 3});
assert.eq(2, t.find({x: {$ne: 2}}).itcount(), "A");
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq(2, t.find({x: {$ne: 2}}).itcount(), "B");
diff --git a/jstests/core/ne2.js b/jstests/core/ne2.js
index 5fef4f1d630..db2ee7b01e5 100644
--- a/jstests/core/ne2.js
+++ b/jstests/core/ne2.js
@@ -5,7 +5,7 @@
t = db.jstests_ne2;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: -0.5});
t.save({a: 0});
diff --git a/jstests/core/nestedarr1.js b/jstests/core/nestedarr1.js
index 248a70b5f78..7edef9db512 100644
--- a/jstests/core/nestedarr1.js
+++ b/jstests/core/nestedarr1.js
@@ -21,7 +21,7 @@ function makeNestArr(depth) {
let collection = db.arrNestTest;
collection.drop();
-assert.commandWorked(collection.createIndex({a: 1}));
+assert.commandWorked(collection.ensureIndex({a: 1}));
const kMaxDocumentDepthSoftLimit = 100;
const kJavaScriptMaxDepthLimit = 150;
diff --git a/jstests/core/nestedobj1.js b/jstests/core/nestedobj1.js
index ba97f326934..44fdd4599d7 100644
--- a/jstests/core/nestedobj1.js
+++ b/jstests/core/nestedobj1.js
@@ -19,7 +19,7 @@ function makeNestObj(depth) {
let collection = db.objNestTest;
collection.drop();
-assert.commandWorked(collection.createIndex({a: 1}));
+assert.commandWorked(collection.ensureIndex({a: 1}));
const kMaxDocumentDepthSoftLimit = 100;
const kJavaScriptMaxDepthLimit = 150;
diff --git a/jstests/core/nin.js b/jstests/core/nin.js
index b9887e48828..d8a254357ba 100644
--- a/jstests/core/nin.js
+++ b/jstests/core/nin.js
@@ -57,5 +57,5 @@ doTest = function(n) {
doTest("no index");
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
doTest("with index");
diff --git a/jstests/core/not1.js b/jstests/core/not1.js
index 0726895ebbd..1039ae7c910 100644
--- a/jstests/core/not1.js
+++ b/jstests/core/not1.js
@@ -16,5 +16,5 @@ function test(name) {
}
test("no index");
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
test("with index");
diff --git a/jstests/core/not2.js b/jstests/core/not2.js
index 31b2efcfa02..0cd9209ce2d 100644
--- a/jstests/core/not2.js
+++ b/jstests/core/not2.js
@@ -86,6 +86,6 @@ function doTest() {
doTest();
// Run the test with an index present.
-assert.commandWorked(coll.createIndex({i: 1}));
+assert.commandWorked(coll.ensureIndex({i: 1}));
doTest();
}());
diff --git a/jstests/core/not3.js b/jstests/core/not3.js
index eac6bf8f047..9f3014f2c1a 100644
--- a/jstests/core/not3.js
+++ b/jstests/core/not3.js
@@ -4,7 +4,7 @@
var t = db.jstests_not3;
t.drop();
-t.createIndex({arr: 1});
+t.ensureIndex({arr: 1});
t.save({_id: 0, arr: [1, 2, 3]});
t.save({_id: 1, arr: [10, 11]});
diff --git a/jstests/core/notablescan.js b/jstests/core/notablescan.js
index adad7f1b725..eca1bd2e787 100644
--- a/jstests/core/notablescan.js
+++ b/jstests/core/notablescan.js
@@ -44,7 +44,7 @@ try {
assert.includes(err.toString(),
"hint $natural is not allowed, because 'notablescan' is enabled");
- t.createIndex({a: 1});
+ t.ensureIndex({a: 1});
assert.eq(0, t.find({a: 1, b: 1}).itcount());
assert.eq(1, t.find({a: 1, b: null}).itcount());
diff --git a/jstests/core/numberlong2.js b/jstests/core/numberlong2.js
index dad87fe30aa..4eadb744131 100644
--- a/jstests/core/numberlong2.js
+++ b/jstests/core/numberlong2.js
@@ -8,7 +8,7 @@
t = db.jstests_numberlong2;
t.drop();
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
function chk(longNum) {
t.remove({});
diff --git a/jstests/core/numberlong4.js b/jstests/core/numberlong4.js
index d7d73898b34..f81a9599e21 100644
--- a/jstests/core/numberlong4.js
+++ b/jstests/core/numberlong4.js
@@ -6,7 +6,7 @@ t.drop();
if (0) { // SERVER-3719
- t.createIndex({x: 1});
+ t.ensureIndex({x: 1});
Random.setRandomSeed();
diff --git a/jstests/core/or1.js b/jstests/core/or1.js
index d90947d5f87..c5975a058f2 100644
--- a/jstests/core/or1.js
+++ b/jstests/core/or1.js
@@ -61,13 +61,13 @@ doTest();
// not part of SERVER-1003, but good check for subseq. implementations
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
doTest();
t.drop();
-t.createIndex({b: 1});
+t.ensureIndex({b: 1});
doTest();
t.drop();
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
doTest();
diff --git a/jstests/core/or2.js b/jstests/core/or2.js
index 508b3294931..5b520197eba 100644
--- a/jstests/core/or2.js
+++ b/jstests/core/or2.js
@@ -72,17 +72,17 @@ doTest = function(index) {
doTest(false);
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
doTest();
t.drop();
-t.createIndex({x: 1, a: 1});
+t.ensureIndex({x: 1, a: 1});
doTest();
t.drop();
-t.createIndex({x: 1, b: 1});
+t.ensureIndex({x: 1, b: 1});
doTest();
t.drop();
-t.createIndex({x: 1, a: 1, b: 1});
+t.ensureIndex({x: 1, a: 1, b: 1});
doTest();
diff --git a/jstests/core/or3.js b/jstests/core/or3.js
index 26628927c87..22a26d571ca 100644
--- a/jstests/core/or3.js
+++ b/jstests/core/or3.js
@@ -63,17 +63,17 @@ doTest = function(index) {
doTest(false);
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
doTest();
t.drop();
-t.createIndex({x: 1, a: 1});
+t.ensureIndex({x: 1, a: 1});
doTest();
t.drop();
-t.createIndex({x: 1, b: 1});
+t.ensureIndex({x: 1, b: 1});
doTest();
t.drop();
-t.createIndex({x: 1, a: 1, b: 1});
+t.ensureIndex({x: 1, a: 1, b: 1});
doTest();
diff --git a/jstests/core/or4.js b/jstests/core/or4.js
index e095eb9961c..f065ccbec86 100644
--- a/jstests/core/or4.js
+++ b/jstests/core/or4.js
@@ -14,8 +14,8 @@ const coll = db.or4;
coll.drop();
db.getCollection("mrOutput").drop();
-coll.createIndex({a: 1});
-coll.createIndex({b: 1});
+coll.ensureIndex({a: 1});
+coll.ensureIndex({b: 1});
assert.commandWorked(coll.insert({a: 2}));
assert.commandWorked(coll.insert({b: 3}));
diff --git a/jstests/core/or5.js b/jstests/core/or5.js
index eed4c3fc62d..40d7792eeeb 100644
--- a/jstests/core/or5.js
+++ b/jstests/core/or5.js
@@ -6,10 +6,10 @@
t = db.jstests_or5;
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
-t.createIndex({c: 1});
+t.ensureIndex({c: 1});
t.save({a: 2});
t.save({b: 3});
@@ -36,7 +36,7 @@ for (i = 2; i <= 7; ++i) {
assert.eq.automsg("6", "t.find( {$or:[{a:2},{b:3},{c:6}]} ).batchSize( i ).toArray().length");
}
-t.createIndex({z: "2d"});
+t.ensureIndex({z: "2d"});
assert.throws.automsg(function() {
return t.find({$or: [{z: {$near: [50, 50]}}, {a: 2}]}).toArray();
@@ -45,9 +45,9 @@ assert.throws.automsg(function() {
function reset() {
t.drop();
- t.createIndex({a: 1});
- t.createIndex({b: 1});
- t.createIndex({c: 1});
+ t.ensureIndex({a: 1});
+ t.ensureIndex({b: 1});
+ t.ensureIndex({c: 1});
t.save({a: 2});
t.save({a: 2});
diff --git a/jstests/core/or6.js b/jstests/core/or6.js
index 7b18e1c219a..144f9ed7e9e 100644
--- a/jstests/core/or6.js
+++ b/jstests/core/or6.js
@@ -6,8 +6,8 @@
var t = db.jstests_orq;
t.drop();
-t.createIndex({a: 1, c: 1});
-t.createIndex({b: 1, c: 1});
+t.ensureIndex({a: 1, c: 1});
+t.ensureIndex({b: 1, c: 1});
t.save({a: 1, c: 9});
t.save({a: 1, c: 10});
diff --git a/jstests/core/or7.js b/jstests/core/or7.js
index e639a195739..d824a90aa81 100644
--- a/jstests/core/or7.js
+++ b/jstests/core/or7.js
@@ -3,7 +3,7 @@
t = db.jstests_or7;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: 2});
assert.eq.automsg("1", "t.count( {$or:[{a:{$in:[1,3]}},{a:2}]} )");
diff --git a/jstests/core/or8.js b/jstests/core/or8.js
index 4af81ec4829..41537dbdf83 100644
--- a/jstests/core/or8.js
+++ b/jstests/core/or8.js
@@ -14,7 +14,7 @@ t.find({"$or": [{"PropA": {"$lt": "b"}}, {"PropA": {"$lt": "b", "$gt": "a"}}]}).
t.save({a: 1});
t.save({a: 3});
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.find({$or: [{a: {$in: []}}]}).toArray();
assert.eq.automsg("2", "t.find({ $or: [ { a: {$in:[]} }, {a:1}, {a:3} ] } ).toArray().length");
assert.eq.automsg("2", "t.find({ $or: [ {a:1}, { a: {$in:[]} }, {a:3} ] } ).toArray().length");
@@ -24,8 +24,8 @@ assert.eq.automsg("2", "t.find({ $or: [ {a:1}, {a:3}, { a: {$in:[]} } ] } ).toAr
t.drop();
t.save({a: {b: 1, c: 1}});
-t.createIndex({'a.b': 1});
-t.createIndex({'a.c': 1});
+t.ensureIndex({'a.b': 1});
+t.ensureIndex({'a.c': 1});
assert.eq(1, t.find({$or: [{'a.b': 1}, {'a.c': 1}]}).itcount());
t.remove({});
diff --git a/jstests/core/or9.js b/jstests/core/or9.js
index 4938e84ca04..68814c684cb 100644
--- a/jstests/core/or9.js
+++ b/jstests/core/or9.js
@@ -5,7 +5,7 @@
t = db.jstests_or9;
t.drop();
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
t.save({a: 2, b: 2});
diff --git a/jstests/core/or_inexact.js b/jstests/core/or_inexact.js
index 0584be98d6d..d6a51d66259 100644
--- a/jstests/core/or_inexact.js
+++ b/jstests/core/or_inexact.js
@@ -20,7 +20,7 @@ var cursor;
// Case 1: An EXACT predicate and an INEXACT_COVERED
t.drop();
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
t.insert({_id: 0, name: "thomas"});
t.insert({_id: 1, name: "alexandra"});
cursor = t.find({$or: [{name: "thomas"}, {name: /^alexand(er|ra)/}]});
@@ -28,7 +28,7 @@ assert.eq(2, cursor.itcount(), "case 1");
// Case 2: Two INEXACT_COVERED predicates.
t.drop();
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
t.insert({_id: 0, name: "thomas"});
t.insert({_id: 1, name: "alexandra"});
cursor = t.find({$or: [{name: /omas/}, {name: /^alexand(er|ra)/}]});
@@ -36,7 +36,7 @@ assert.eq(2, cursor.itcount(), "case 2");
// Case 3: An EXACT, and INEXACT_COVERED, and an INEXACT_FETCH.
t.drop();
-t.createIndex({names: 1});
+t.ensureIndex({names: 1});
t.insert({_id: 0, names: ["thomas", "alexandra"]});
t.insert({_id: 1, names: "frank"});
t.insert({_id: 2, names: "alice"});
@@ -47,7 +47,7 @@ assert.eq(3, cursor.itcount(), "case 3");
// Case 4: Two INEXACT_FETCH.
t.drop();
-t.createIndex({names: 1});
+t.ensureIndex({names: 1});
t.insert({_id: 0, names: ["thomas", "alexandra"]});
t.insert({_id: 1, names: ["frank", "alice"]});
t.insert({_id: 2, names: "frank"});
@@ -58,8 +58,8 @@ assert.eq(2, cursor.itcount(), "case 4");
// Case 5: Two indices. One has EXACT and INEXACT_COVERED. The other
// has EXACT and INEXACT_FETCH.
t.drop();
-t.createIndex({first: 1});
-t.createIndex({last: 1});
+t.ensureIndex({first: 1});
+t.ensureIndex({last: 1});
t.insert({_id: 0, first: "frank", last: "smith"});
t.insert({_id: 1, first: "john", last: "doe"});
t.insert({_id: 2, first: "dave", last: "st"});
@@ -71,7 +71,7 @@ assert.eq(4, cursor.itcount(), "case 5");
// Case 6: Multikey with only EXACT predicates.
t.drop();
-t.createIndex({names: 1});
+t.ensureIndex({names: 1});
t.insert({_id: 0, names: ["david", "dave"]});
t.insert({_id: 1, names: ["joseph", "joe", "joey"]});
cursor = t.find({$or: [{names: "dave"}, {names: "joe"}]});
@@ -79,7 +79,7 @@ assert.eq(2, cursor.itcount(), "case 6");
// Case 7: Multikey with EXACT and INEXACT_COVERED.
t.drop();
-t.createIndex({names: 1});
+t.ensureIndex({names: 1});
t.insert({_id: 0, names: ["david", "dave"]});
t.insert({_id: 1, names: ["joseph", "joe", "joey"]});
cursor = t.find({$or: [{names: "dave"}, {names: /joe/}]});
@@ -87,8 +87,8 @@ assert.eq(2, cursor.itcount(), "case 7");
// Case 8: Text with EXACT.
t.drop();
-t.createIndex({pre: 1, names: "text"});
-t.createIndex({other: 1});
+t.ensureIndex({pre: 1, names: "text"});
+t.ensureIndex({other: 1});
t.insert({_id: 0, pre: 3, names: "david dave", other: 1});
t.insert({_id: 1, pre: 4, names: "joseph joe joey", other: 2});
cursor = t.find({$or: [{$text: {$search: "dave"}, pre: 3}, {other: 2}]});
@@ -96,8 +96,8 @@ assert.eq(2, cursor.itcount(), "case 8");
// Case 9: Text with INEXACT_COVERED.
t.drop();
-t.createIndex({pre: 1, names: "text"});
-t.createIndex({other: 1});
+t.ensureIndex({pre: 1, names: "text"});
+t.ensureIndex({other: 1});
t.insert({_id: 0, pre: 3, names: "david dave", other: "foo"});
t.insert({_id: 1, pre: 5, names: "david dave", other: "foo"});
t.insert({_id: 2, pre: 4, names: "joseph joe joey", other: "bar"});
@@ -106,8 +106,8 @@ assert.eq(2, cursor.itcount(), "case 9");
// Case 10: Text requiring filter with INEXACT_COVERED.
t.drop();
-t.createIndex({pre: 1, names: "text"});
-t.createIndex({other: 1});
+t.ensureIndex({pre: 1, names: "text"});
+t.ensureIndex({other: 1});
t.insert({_id: 0, pre: 3, names: "david dave", other: "foo"});
t.insert({_id: 1, pre: 3, names: "david dave", other: "foo"});
t.insert({_id: 2, pre: 4, names: "joseph joe joey", other: "bar"});
@@ -116,7 +116,7 @@ assert.eq(3, cursor.itcount(), "case 10");
// Case 11: GEO with non-geo, same index, 2dsphere.
t.drop();
-t.createIndex({pre: 1, loc: "2dsphere"});
+t.ensureIndex({pre: 1, loc: "2dsphere"});
t.insert({_id: 0, pre: 3, loc: {type: "Point", coordinates: [40, 5]}});
t.insert({_id: 1, pre: 4, loc: {type: "Point", coordinates: [0, 0]}});
cursor = t.find({
@@ -149,7 +149,7 @@ assert.eq(2, cursor.itcount(), "case 11");
// Case 12: GEO with non-geo, same index, 2d.
t.drop();
-t.createIndex({pre: 1, loc: "2d"});
+t.ensureIndex({pre: 1, loc: "2d"});
t.insert({_id: 0, pre: 3, loc: {type: "Point", coordinates: [40, 5]}});
t.insert({_id: 1, pre: 4, loc: {type: "Point", coordinates: [0, 0]}});
cursor = t.find({
@@ -182,7 +182,7 @@ assert.eq(2, cursor.itcount(), "case 12");
// Case 13: $elemMatch object.
t.drop();
-t.createIndex({"a.b": 1});
+t.ensureIndex({"a.b": 1});
t.insert({_id: 0, a: [{b: 1}, {b: 2}]});
t.insert({_id: 1, a: [{b: 3}, {b: 4}]});
cursor = t.find({$or: [{a: {$elemMatch: {b: {$lte: 1}}}}, {a: {$elemMatch: {b: {$gte: 4}}}}]});
@@ -190,7 +190,7 @@ assert.eq(2, cursor.itcount(), "case 13");
// Case 14: $elemMatch object, below an AND.
t.drop();
-t.createIndex({"a.b": 1});
+t.ensureIndex({"a.b": 1});
t.insert({_id: 0, a: [{b: 1}, {b: 2}]});
t.insert({_id: 1, a: [{b: 2}, {b: 4}]});
cursor =
@@ -199,7 +199,7 @@ assert.eq(2, cursor.itcount(), "case 14");
// Case 15: $or below $elemMatch.
t.drop();
-t.createIndex({"a.b": 1});
+t.ensureIndex({"a.b": 1});
t.insert({_id: 0, a: [{b: 1}, {b: 2}]});
t.insert({_id: 1, a: [{b: 2}, {b: 4}]});
t.insert({_id: 2, a: {b: 4}});
@@ -208,7 +208,7 @@ assert.eq(2, cursor.itcount(), "case 15");
// Case 16: $or below $elemMatch with INEXACT_COVERED.
t.drop();
-t.createIndex({"a.b": 1});
+t.ensureIndex({"a.b": 1});
t.insert({_id: 0, a: [{b: "x"}, {b: "y"}]});
t.insert({_id: 1, a: [{b: "y"}, {b: ["y", "z"]}]});
t.insert({_id: 2, a: {b: ["y", "z"]}});
@@ -217,7 +217,7 @@ assert.eq(2, cursor.itcount(), "case 16");
// Case 17: case from SERVER-14030.
t.drop();
-t.createIndex({number: 1});
+t.ensureIndex({number: 1});
t.insert({number: null, user_id: 1});
t.insert({number: 2, user_id: 1});
t.insert({number: 1, user_id: 1});
@@ -226,7 +226,7 @@ assert.eq(3, cursor.itcount(), "case 17");
// Case 18: $in with EXACT and INEXACT_COVERED.
t.drop();
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
t.insert({_id: 0, name: "thomas"});
t.insert({_id: 1, name: "alexandra"});
cursor = t.find({name: {$in: ["thomas", /^alexand(er|ra)/]}});
@@ -234,7 +234,7 @@ assert.eq(2, cursor.itcount(), "case 18");
// Case 19: $in with EXACT, INEXACT_COVERED, and INEXACT_FETCH.
t.drop();
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
t.insert({_id: 0, name: "thomas"});
t.insert({_id: 1, name: "alexandra"});
t.insert({_id: 2});
@@ -243,8 +243,8 @@ assert.eq(3, cursor.itcount(), "case 19");
// Case 20: $in with EXACT, INEXACT_COVERED, and INEXACT_FETCH, two indices.
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
t.insert({_id: 0, a: "x", b: "y"});
t.insert({_id: 1, a: "z", b: "z"});
t.insert({_id: 2});
@@ -256,7 +256,7 @@ assert.eq(5, cursor.itcount(), "case 19");
// Case 21: two $geoWithin that collapse to a single GEO index scan.
t.drop();
-t.createIndex({loc: "2dsphere"});
+t.ensureIndex({loc: "2dsphere"});
t.insert({_id: 0, loc: {type: "Point", coordinates: [40, 5]}});
t.insert({_id: 1, loc: {type: "Point", coordinates: [0, 0]}});
cursor = t.find({
diff --git a/jstests/core/ora.js b/jstests/core/ora.js
index ca07516cae3..06d8f39c48f 100644
--- a/jstests/core/ora.js
+++ b/jstests/core/ora.js
@@ -19,7 +19,7 @@ assert.eq.automsg("10", "t.find({$or: [{$where: 'this.x === 2'}, {x: {$ne: 2}}]}
// geo
t.drop();
-t.createIndex({loc: "2d"});
+t.ensureIndex({loc: "2d"});
assert.throws(function() {
t.find({$or: [{loc: {$near: [11, 11]}}]}).limit(1).next();
diff --git a/jstests/core/orb.js b/jstests/core/orb.js
index aa75bb97e0b..345ac92d26e 100644
--- a/jstests/core/orb.js
+++ b/jstests/core/orb.js
@@ -4,14 +4,14 @@ var t = db.jstests_orb;
t.drop();
t.save({a: 1});
-t.createIndex({a: -1});
+t.ensureIndex({a: -1});
assert.eq.automsg("1", "t.count( {$or: [ { a: { $gt:0,$lt:2 } }, { a: { $gt:-1,$lt:3 } } ] } )");
t.drop();
t.save({a: 1, b: 1});
-t.createIndex({a: 1, b: -1});
+t.ensureIndex({a: 1, b: -1});
assert.eq.automsg("1", "t.count( {$or: [ { a: { $gt:0,$lt:2 } }, { a: { $gt:-1,$lt:3 } } ] } )");
assert.eq.automsg(
diff --git a/jstests/core/orc.js b/jstests/core/orc.js
index 001d6f4bc9f..dc46d6de4ad 100644
--- a/jstests/core/orc.js
+++ b/jstests/core/orc.js
@@ -20,7 +20,7 @@ t.drop();
// possible to write a more
// robust test.
-t.createIndex({a: -1, b: 1, c: 1});
+t.ensureIndex({a: -1, b: 1, c: 1});
// sanity test
t.save({a: null, b: 4, c: 4});
diff --git a/jstests/core/ord.js b/jstests/core/ord.js
index 4a76f831246..ddbae540ffc 100644
--- a/jstests/core/ord.js
+++ b/jstests/core/ord.js
@@ -16,8 +16,8 @@ load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers.
const t = db.jstests_ord;
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
for (let i = 0; i < 80; ++i) {
t.save({a: 1});
diff --git a/jstests/core/ore.js b/jstests/core/ore.js
index 756db6215c5..959f43f5101 100644
--- a/jstests/core/ore.js
+++ b/jstests/core/ore.js
@@ -4,8 +4,8 @@
t = db.jstests_ore;
t.drop();
-t.createIndex({a: -1});
-t.createIndex({b: 1});
+t.ensureIndex({a: -1});
+t.ensureIndex({b: 1});
t.save({a: 1, b: 1});
t.save({a: 2, b: 1});
diff --git a/jstests/core/org.js b/jstests/core/org.js
index 0c6808330c8..7479db062e4 100644
--- a/jstests/core/org.js
+++ b/jstests/core/org.js
@@ -5,8 +5,8 @@
t = db.jstests_org;
t.drop();
-t.createIndex({a: 1}, {sparse: true});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1}, {sparse: true});
+t.ensureIndex({b: 1});
t.remove({});
t.save({a: 1, b: 2});
diff --git a/jstests/core/orh.js b/jstests/core/orh.js
index 91ce121e5a4..1ceed1d501f 100644
--- a/jstests/core/orh.js
+++ b/jstests/core/orh.js
@@ -5,8 +5,8 @@
t = db.jstests_orh;
t.drop();
-t.createIndex({a: 1}, {sparse: true});
-t.createIndex({b: 1, a: 1});
+t.ensureIndex({a: 1}, {sparse: true});
+t.ensureIndex({b: 1, a: 1});
t.remove({});
t.save({b: 2});
diff --git a/jstests/core/orj.js b/jstests/core/orj.js
index deee0c4821c..0ec304d9e52 100644
--- a/jstests/core/orj.js
+++ b/jstests/core/orj.js
@@ -84,26 +84,26 @@ function check() {
check();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
check();
t.dropIndexes();
-t.createIndex({b: 1});
+t.ensureIndex({b: 1});
check();
t.dropIndexes();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
check();
t.dropIndexes();
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
check();
t.dropIndexes();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
+t.ensureIndex({a: 1, b: 1});
check();
function checkHinted(hint) {
diff --git a/jstests/core/ork.js b/jstests/core/ork.js
index 9079d3819ba..7f203c74e5f 100644
--- a/jstests/core/ork.js
+++ b/jstests/core/ork.js
@@ -6,7 +6,7 @@
t = db.jstests_ork;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: [1, 2], b: 5});
t.save({a: [2, 4], b: 5});
diff --git a/jstests/core/oro.js b/jstests/core/oro.js
index aa884d306c6..80684869f6d 100644
--- a/jstests/core/oro.js
+++ b/jstests/core/oro.js
@@ -13,7 +13,7 @@ orClauses = [];
for (idxKey = 'a'; idxKey <= 'aaaaaaaaaa'; idxKey += 'a') {
idx = {};
idx[idxKey] = 1;
- t.createIndex(idx);
+ t.ensureIndex(idx);
for (i = 0; i < 200; ++i) {
t.insert(idx);
}
diff --git a/jstests/core/orp.js b/jstests/core/orp.js
index a2918fc5a56..a706d6f4c1a 100644
--- a/jstests/core/orp.js
+++ b/jstests/core/orp.js
@@ -4,9 +4,9 @@
t = db.jstests_orp;
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
-t.createIndex({c: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
+t.ensureIndex({c: 1});
for (i = 0; i < 200; ++i) {
t.save({a: 1, b: 1});
@@ -23,7 +23,7 @@ assert.eq(201, t.count({$or: [{a: 1}, {c: 1}, {b: 1}]}));
// Deduping results that would normally be index only matches on overlapping and double scanned $or
// field regions.
t.drop();
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
for (i = 0; i < 16; ++i) {
for (j = 0; j < 16; ++j) {
t.save({a: i, b: j});
@@ -33,8 +33,8 @@ assert.eq(16 * 16, t.count({$or: [{a: {$gte: 0}, b: {$gte: 0}}, {a: {$lte: 16},
// Deduping results from a clause that completed before the multi cursor takeover.
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
t.save({a: 1, b: 200});
for (i = 0; i < 200; ++i) {
t.save({b: i});
diff --git a/jstests/core/profile_list_indexes.js b/jstests/core/profile_list_indexes.js
index 92389bf5642..359dd9e85cf 100644
--- a/jstests/core/profile_list_indexes.js
+++ b/jstests/core/profile_list_indexes.js
@@ -19,7 +19,7 @@ const numIndexes = 5;
for (let i = 0; i < numIndexes; ++i) {
let indexSpec = {};
indexSpec["fakeField_" + i] = 1;
- assert.commandWorked(testColl.createIndex(indexSpec));
+ assert.commandWorked(testColl.ensureIndex(indexSpec));
}
testDB.setProfilingLevel(2);
diff --git a/jstests/core/proj_key1.js b/jstests/core/proj_key1.js
index 51ca23d0c37..af6d6d9d9fe 100644
--- a/jstests/core/proj_key1.js
+++ b/jstests/core/proj_key1.js
@@ -13,7 +13,7 @@ for (i = 0; i < 10; i++) {
t.insert({a: i, b: i});
}
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq(as, t.find({a: {$gte: 0}}, {a: 1, _id: 0}).sort({a: 1}).toArray());
assert.eq(as, t.find({a: {$gte: 0}}, {a: 1, _id: 0}).sort({a: 1}).batchSize(2).toArray());
diff --git a/jstests/core/queryoptimizera.js b/jstests/core/queryoptimizera.js
index 55d0d5c424a..5daccbba232 100644
--- a/jstests/core/queryoptimizera.js
+++ b/jstests/core/queryoptimizera.js
@@ -83,7 +83,7 @@ t.find({_id: 0, a: 0}).itcount();
assertNoNewWarnings();
// Warnings should not be printed when an index is added on _id.
-t.createIndex({_id: 1});
+t.ensureIndex({_id: 1});
t.find({_id: 0}).itcount();
assertNoNewWarnings();
diff --git a/jstests/core/record_store_count.js b/jstests/core/record_store_count.js
index f89f1cfea17..89dcf8d4cdc 100644
--- a/jstests/core/record_store_count.js
+++ b/jstests/core/record_store_count.js
@@ -15,7 +15,7 @@ coll.drop();
assert.commandWorked(coll.insert({x: 0}));
assert.commandWorked(coll.insert({x: 1}));
-assert.commandWorked(coll.createIndex({x: 1}));
+assert.commandWorked(coll.ensureIndex({x: 1}));
//
// Logically empty predicates should use the record store's count.
@@ -78,7 +78,7 @@ const kNewIndexSpec = {
x: 1,
_id: 1
};
-assert.commandWorked(coll.createIndex(kNewIndexSpec));
+assert.commandWorked(coll.ensureIndex(kNewIndexSpec));
testExplainAndExpectStage({
expectedStages: ["COUNT", "SHARDING_FILTER"],
unexpectedStages: ["FETCH"],
diff --git a/jstests/core/regex3.js b/jstests/core/regex3.js
index 158d0607647..46b18c03028 100644
--- a/jstests/core/regex3.js
+++ b/jstests/core/regex3.js
@@ -14,7 +14,7 @@ t.save({name: "aaron"});
assert.eq(2, t.find({name: /^e.*/}).itcount(), "no index count");
assert.eq(
4, t.find({name: /^e.*/}).explain(true).executionStats.totalDocsExamined, "no index explain");
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
assert.eq(2, t.find({name: /^e.*/}).itcount(), "index count");
assert.eq(2,
t.find({name: /^e.*/}).explain(true).executionStats.totalKeysExamined,
@@ -28,7 +28,7 @@ t.save({name: "ac"});
t.save({name: "c"});
assert.eq(3, t.find({name: /^aa*/}).itcount(), "B ni");
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
assert.eq(3, t.find({name: /^aa*/}).itcount(), "B i 1");
assert.eq(4, t.find({name: /^aa*/}).explain(true).executionStats.totalKeysExamined, "B i 1 e");
@@ -39,5 +39,5 @@ t.drop();
t.save({name: ""});
assert.eq(1, t.find({name: /^a?/}).itcount(), "C 1");
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
assert.eq(1, t.find({name: /^a?/}).itcount(), "C 2");
diff --git a/jstests/core/regex4.js b/jstests/core/regex4.js
index 0e631082352..4ced6d06924 100644
--- a/jstests/core/regex4.js
+++ b/jstests/core/regex4.js
@@ -17,7 +17,7 @@ assert.eq(
// assert.eq( 2 , t.find( { name : { $ne : /^e.*/ } } ).count() , "no index count ne" ); //
// SERVER-251
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
assert.eq(2, t.find({name: /^e.*/}).count(), "index count");
assert.eq(2,
diff --git a/jstests/core/regex5.js b/jstests/core/regex5.js
index d0836a62686..69537e149e5 100644
--- a/jstests/core/regex5.js
+++ b/jstests/core/regex5.js
@@ -31,7 +31,7 @@ doit = function() {
};
doit();
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
print("now indexed");
doit();
diff --git a/jstests/core/regex6.js b/jstests/core/regex6.js
index f21152d8c55..7af6c7d8400 100644
--- a/jstests/core/regex6.js
+++ b/jstests/core/regex6.js
@@ -14,7 +14,7 @@ t.save({name: "bob"});
t.save({name: "aaron"});
t.save({name: "[with]some?symbols"});
-t.createIndex({name: 1});
+t.ensureIndex({name: 1});
assert.eq(0, t.find({name: /^\//}).count(), "index count");
assert.eq(
diff --git a/jstests/core/regex7.js b/jstests/core/regex7.js
index f864f29be8e..290cbe387a9 100644
--- a/jstests/core/regex7.js
+++ b/jstests/core/regex7.js
@@ -17,7 +17,7 @@ assert.eq(/^b/, t.findOne({r: /^b/}).r, '3 1 a');
assert.eq(1, t.count({r: /^b/}), '3 2 a');
// with index
-t.createIndex({r: 1});
+t.ensureIndex({r: 1});
assert.eq(/^a/, t.findOne({r: /^a/}).r, '1 1 b');
assert.eq(1, t.count({r: /^a/}), '1 2 b');
assert.eq(/^a/i, t.findOne({r: /^a/i}).r, '2 1 b');
diff --git a/jstests/core/regex8.js b/jstests/core/regex8.js
index d65a6836b26..c92e82e4aa6 100644
--- a/jstests/core/regex8.js
+++ b/jstests/core/regex8.js
@@ -20,5 +20,5 @@ function test(msg) {
test("A");
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
test("B");
diff --git a/jstests/core/regex_embed1.js b/jstests/core/regex_embed1.js
index c74ffb4aa32..baaa8937962 100644
--- a/jstests/core/regex_embed1.js
+++ b/jstests/core/regex_embed1.js
@@ -23,5 +23,5 @@ function test(m) {
test("A");
-t.createIndex({"a.x": 1});
+t.ensureIndex({"a.x": 1});
test("B");
diff --git a/jstests/core/regexa.js b/jstests/core/regexa.js
index 694436e87a8..b56e2cf405e 100644
--- a/jstests/core/regexa.js
+++ b/jstests/core/regexa.js
@@ -13,7 +13,7 @@ function check() {
t.save({a: 'a'});
check();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
if (1) { // SERVER-3298
check();
}
diff --git a/jstests/core/regexc.js b/jstests/core/regexc.js
index e9e2ba613aa..d7df4f7d574 100644
--- a/jstests/core/regexc.js
+++ b/jstests/core/regexc.js
@@ -7,7 +7,7 @@ var t = db.jstests_regexc;
// $and using same index twice
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: "0"});
t.save({a: "1"});
t.save({a: "10"});
@@ -15,7 +15,7 @@ assert.eq(1, t.find({$and: [{a: /0/}, {a: /1/}]}).itcount());
// implicit $and using compound index twice
t.drop();
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
t.save({a: "0", b: "1"});
t.save({a: "10", b: "10"});
t.save({a: "10", b: "2"});
@@ -23,7 +23,7 @@ assert.eq(2, t.find({a: /0/, b: /1/}).itcount());
// $or using same index twice
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({a: "0"});
t.save({a: "1"});
t.save({a: "2"});
diff --git a/jstests/core/remove.js b/jstests/core/remove.js
index f08792aeca5..37754c74190 100644
--- a/jstests/core/remove.js
+++ b/jstests/core/remove.js
@@ -6,7 +6,7 @@
t = db.removetest;
function f(n, dir) {
- t.createIndex({x: dir || 1});
+ t.ensureIndex({x: dir || 1});
for (i = 0; i < n; i++)
t.save({x: 3, z: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"});
diff --git a/jstests/core/remove2.js b/jstests/core/remove2.js
index 4193b8dd11f..d01c1e2e58c 100644
--- a/jstests/core/remove2.js
+++ b/jstests/core/remove2.js
@@ -38,10 +38,10 @@ f();
t.drop();
g();
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
t.remove({});
f();
t.drop();
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
g();
})();
diff --git a/jstests/core/remove6.js b/jstests/core/remove6.js
index f60200a8d81..b91d28fa4e5 100644
--- a/jstests/core/remove6.js
+++ b/jstests/core/remove6.js
@@ -23,7 +23,7 @@ function test(n, idx) {
pop();
assert.eq(N, t.count(), n + " A " + idx);
if (idx)
- t.createIndex(idx);
+ t.ensureIndex(idx);
var res = del();
assert(!res.hasWriteError(), "error deleting: " + res.toString());
assert.eq(0, t.count(), n + " B " + idx);
diff --git a/jstests/core/remove7.js b/jstests/core/remove7.js
index 9cc86329990..4a1548fbce2 100644
--- a/jstests/core/remove7.js
+++ b/jstests/core/remove7.js
@@ -18,7 +18,7 @@ for (i = 0; i < 1000; i++) {
t.save({tags: getTags()});
}
-t.createIndex({tags: 1});
+t.ensureIndex({tags: 1});
for (i = 0; i < 200; i++) {
for (var j = 0; j < 10; j++)
diff --git a/jstests/core/remove9.js b/jstests/core/remove9.js
index 4962dd9a06f..dc3f84a9c34 100644
--- a/jstests/core/remove9.js
+++ b/jstests/core/remove9.js
@@ -13,7 +13,7 @@
const t = db.jstests_remove9;
t.drop();
-t.createIndex({i: 1});
+t.ensureIndex({i: 1});
const bulk = t.initializeUnorderedBulkOp();
for (let i = 0; i < 1000; ++i) {
diff --git a/jstests/core/removea.js b/jstests/core/removea.js
index 9fd489b7005..2c45ee665f4 100644
--- a/jstests/core/removea.js
+++ b/jstests/core/removea.js
@@ -10,7 +10,7 @@ Random.setRandomSeed();
for (let v = 0; v < 2; ++v) { // Try each index version.
t.drop();
- t.createIndex({a: 1}, {v: v});
+ t.ensureIndex({a: 1}, {v: v});
const S = 100;
const B = 100;
for (let x = 0; x < S; x++) {
diff --git a/jstests/core/removeb.js b/jstests/core/removeb.js
index d4ea12aa8f6..b81c0818d21 100644
--- a/jstests/core/removeb.js
+++ b/jstests/core/removeb.js
@@ -13,7 +13,7 @@
const t = db.jstests_removeb;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
// Make the index multikey to trigger cursor dedup checking.
t.insert({a: [-1, -2]});
diff --git a/jstests/core/removec.js b/jstests/core/removec.js
index 560f7405de3..500437e8891 100644
--- a/jstests/core/removec.js
+++ b/jstests/core/removec.js
@@ -8,7 +8,7 @@
t = db.jstests_removec;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
/** @return an array containing a sequence of numbers from i to i + 10. */
function runStartingWith(i) {
diff --git a/jstests/core/rename.js b/jstests/core/rename.js
index a8d888393b5..08d254bbe29 100644
--- a/jstests/core/rename.js
+++ b/jstests/core/rename.js
@@ -12,8 +12,8 @@ c.drop();
a.save({a: 1});
a.save({a: 2});
-a.createIndex({a: 1});
-a.createIndex({b: 1});
+a.ensureIndex({a: 1});
+a.ensureIndex({b: 1});
c.save({a: 100});
assert.commandFailed(
diff --git a/jstests/core/rename4.js b/jstests/core/rename4.js
index 98a9dd80d11..1ce3b30f177 100644
--- a/jstests/core/rename4.js
+++ b/jstests/core/rename4.js
@@ -124,7 +124,7 @@ good({a: 1, c: 4}, {$rename: {b: 'c.d'}}, {a: 1, c: 4});
// check index
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
function l(start, mod, query, expected) {
t.remove({});
diff --git a/jstests/core/rename5.js b/jstests/core/rename5.js
index 3d5646c7ee5..357d67fc9ee 100644
--- a/jstests/core/rename5.js
+++ b/jstests/core/rename5.js
@@ -5,7 +5,7 @@
t = db.jstests_rename5;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
t.save({b: 1});
t.update({}, {$rename: {a: 'b'}});
diff --git a/jstests/core/rename6.js b/jstests/core/rename6.js
index 1122623c165..faa36a448dd 100644
--- a/jstests/core/rename6.js
+++ b/jstests/core/rename6.js
@@ -17,7 +17,7 @@ const dbd = testDB.getCollection(d);
dbc.drop();
dbd.drop();
-dbc.createIndex({
+dbc.ensureIndex({
"name": 1,
"date": 1,
"time": 1,
diff --git a/jstests/core/rename7.js b/jstests/core/rename7.js
index a538f36e2dc..8f209e83acd 100644
--- a/jstests/core/rename7.js
+++ b/jstests/core/rename7.js
@@ -28,8 +28,8 @@ b.drop();
a.save({a: 1});
a.save({a: 2});
a.save({a: 3});
-a.createIndex({a: 1});
-a.createIndex({b: 1});
+a.ensureIndex({a: 1});
+a.ensureIndex({b: 1});
assert.commandWorked(admin.runCommand({renameCollection: "db_a.rename7", to: "db_b.rename7"}));
diff --git a/jstests/core/return_key.js b/jstests/core/return_key.js
index 96c6284ebf4..9d30477bd54 100644
--- a/jstests/core/return_key.js
+++ b/jstests/core/return_key.js
@@ -24,8 +24,8 @@ assert.commandWorked(coll.insert({a: 1, b: 3}));
assert.commandWorked(coll.insert({a: 2, b: 2}));
assert.commandWorked(coll.insert({a: 3, b: 1}));
-assert.commandWorked(coll.createIndex({a: 1}));
-assert.commandWorked(coll.createIndex({b: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({b: 1}));
// Basic returnKey.
results = coll.find().hint({a: 1}).sort({a: 1}).returnKey().toArray();
diff --git a/jstests/core/server14747.js b/jstests/core/server14747.js
index c792f214259..f9a650defa4 100644
--- a/jstests/core/server14747.js
+++ b/jstests/core/server14747.js
@@ -10,8 +10,8 @@
var t = db.jstests_server14747;
t.drop();
-t.createIndex({a: 1, b: 1});
-t.createIndex({a: 1, c: 1});
+t.ensureIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, c: 1});
t.insert({a: 1});
for (var i = 0; i < 10; i++) {
t.find({a: 1}).explain(true);
diff --git a/jstests/core/server14753.js b/jstests/core/server14753.js
index 4fac2e06485..e8de183f2d7 100644
--- a/jstests/core/server14753.js
+++ b/jstests/core/server14753.js
@@ -7,8 +7,8 @@
var t = db.jstests_server14753;
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
for (var i = 0; i < 20; i++) {
t.insert({b: i});
}
diff --git a/jstests/core/server9547.js b/jstests/core/server9547.js
index 5e2d6aba566..66b17644e15 100644
--- a/jstests/core/server9547.js
+++ b/jstests/core/server9547.js
@@ -8,7 +8,7 @@ for (var i = 0; i < 10; i++) {
t.save({a: i});
}
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
// note: max() value is exclusive upper bound
assert.eq(4, t.find({}).max({a: 4}).hint({a: 1}).toArray().length, "no order");
diff --git a/jstests/core/set_type_change.js b/jstests/core/set_type_change.js
index a0976b3ea44..12035cc39a9 100644
--- a/jstests/core/set_type_change.js
+++ b/jstests/core/set_type_change.js
@@ -12,7 +12,7 @@
var coll = db.set_type_change;
coll.drop();
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
assert.commandWorked(coll.insert({a: 2}));
diff --git a/jstests/core/show_record_id.js b/jstests/core/show_record_id.js
index 0f2df332354..d111858bc7d 100644
--- a/jstests/core/show_record_id.js
+++ b/jstests/core/show_record_id.js
@@ -25,7 +25,7 @@ t.save({});
checkResults(t.find().batchSize(2).showRecordId().toArray());
// Check with a covered index.
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
checkResults(t.find({}, {_id: 0, a: 1}).hint({a: 1}).showRecordId().toArray());
checkResults(t.find({}, {_id: 0, a: 1}).hint({a: 1}).showRecordId().toArray());
diff --git a/jstests/core/skip1.js b/jstests/core/skip1.js
index 3b99e6b4cdd..ae8f589d616 100644
--- a/jstests/core/skip1.js
+++ b/jstests/core/skip1.js
@@ -6,7 +6,7 @@ var t = db.jstests_skip1;
if (0) { // SERVER-2845
t.drop();
- t.createIndex({a: 1});
+ t.ensureIndex({a: 1});
t.save({a: 5});
t.save({a: 5});
t.save({a: 5});
diff --git a/jstests/core/sort1.js b/jstests/core/sort1.js
index 2a11771fd16..39c8d3d333d 100644
--- a/jstests/core/sort1.js
+++ b/jstests/core/sort1.js
@@ -22,7 +22,7 @@ for (var pass = 0; pass < 2; pass++) {
assert(coll.find().sort({x: -1})[1].x == 3);
assert.eq(coll.find().sort({x: -1}).skip(0)[0].x, 5);
assert.eq(coll.find().sort({x: -1}).skip(1)[0].x, 3);
- coll.createIndex({x: 1});
+ coll.ensureIndex({x: 1});
}
assert(coll.validate().valid);
@@ -38,7 +38,7 @@ for (var pass = 0; pass < 2; pass++) {
assert.eq("a", coll.find().sort({'x': 1}).next().x, "c.2");
assert.eq("zed", coll.find().sort({'x': -1}).limit(1).next().x, "c.3");
assert.eq("zed", coll.find().sort({'x': -1}).next().x, "c.4");
- coll.createIndex({x: 1});
+ coll.ensureIndex({x: 1});
}
assert(coll.validate().valid);
diff --git a/jstests/core/sort10.js b/jstests/core/sort10.js
index 6819c76fa5b..167cf74bbfc 100644
--- a/jstests/core/sort10.js
+++ b/jstests/core/sort10.js
@@ -11,7 +11,7 @@ function checkSorting1(opts) {
var d = new Date(-50);
for (var pass = 0; pass < 2; pass++) {
assert(t.find().sort({x: 1})[0].x.valueOf() == d.valueOf());
- t.createIndex({x: 1}, opts);
+ t.ensureIndex({x: 1}, opts);
t.insert({x: new Date()});
}
}
@@ -42,10 +42,10 @@ reverseDates = dates.slice(0).reverse();
checkSorting2(dates, 1);
checkSorting2(reverseDates, -1);
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
checkSorting2(dates, 1);
checkSorting2(reverseDates, -1);
t.dropIndexes();
-t.createIndex({x: -1});
+t.ensureIndex({x: -1});
checkSorting2(dates, 1);
checkSorting2(reverseDates, -1);
diff --git a/jstests/core/sort2.js b/jstests/core/sort2.js
index c584dc48114..ca2d3dc80bf 100644
--- a/jstests/core/sort2.js
+++ b/jstests/core/sort2.js
@@ -15,7 +15,7 @@ for (var pass = 0; pass < 2; pass++) {
assert(res[0].y.a == 2);
assert(res[1].y.a == 5);
assert(res.length == 4);
- t.createIndex({"y.a": 1});
+ t.ensureIndex({"y.a": 1});
}
assert(t.validate().valid);
@@ -31,5 +31,5 @@ for (var pass = 0; pass < 2; pass++) {
for (var i = 0; i < good.length; i++) {
assert(good[i].toString() == res[i].x.toString());
}
- t.createIndex({x: 1});
+ t.ensureIndex({x: 1});
}
diff --git a/jstests/core/sort4.js b/jstests/core/sort4.js
index e74df1f4bd6..0afe2cebe80 100644
--- a/jstests/core/sort4.js
+++ b/jstests/core/sort4.js
@@ -36,10 +36,10 @@ nice({name: 1, prename: 1}, "A,AB,AC,BB,BD", "e1");
assert.commandWorked(coll.insert({name: 'C'}));
nice({name: 1, prename: 1}, "A,AB,AC,BB,BD,C", "e2"); // SERVER-282
-assert.commandWorked(coll.createIndex({name: 1, prename: 1}));
+assert.commandWorked(coll.ensureIndex({name: 1, prename: 1}));
nice({name: 1, prename: 1}, "A,AB,AC,BB,BD,C", "e2ia"); // SERVER-282
assert.commandWorked(coll.dropIndexes());
-assert.commandWorked(coll.createIndex({name: 1}));
+assert.commandWorked(coll.ensureIndex({name: 1}));
nice({name: 1, prename: 1}, "A,AB,AC,BB,BD,C", "e2ib"); // SERVER-282
}());
diff --git a/jstests/core/sort5.js b/jstests/core/sort5.js
index be40802ade4..2f604225d7a 100644
--- a/jstests/core/sort5.js
+++ b/jstests/core/sort5.js
@@ -16,7 +16,7 @@ assert.eq([4, 2, 3, 1],
return z.x;
}),
"A no index");
-t.createIndex({"y.b": 1, "y.a": -1});
+t.ensureIndex({"y.b": 1, "y.a": -1});
assert.eq([4, 2, 3, 1],
t.find().sort({"y.b": 1, "y.a": -1}).map(function(z) {
return z.x;
@@ -31,7 +31,7 @@ assert.eq([4, 2, 3, 1],
return z.x;
}),
"B no index");
-t.createIndex({"y.b": 1, "_id": -1});
+t.ensureIndex({"y.b": 1, "_id": -1});
assert.eq([4, 2, 3, 1],
t.find().sort({"y.b": 1, _id: -1}).map(function(z) {
return z.x;
diff --git a/jstests/core/sort6.js b/jstests/core/sort6.js
index f2658bbcbad..2373969f7f6 100644
--- a/jstests/core/sort6.js
+++ b/jstests/core/sort6.js
@@ -16,7 +16,7 @@ t.insert({_id: 3, c: 2});
assert.eq([3, 2, 1], get(-1), "A1"); // SERVER-635
assert.eq([1, 2, 3], get(1), "A2");
-t.createIndex({c: 1});
+t.ensureIndex({c: 1});
assert.eq([3, 2, 1], get(-1), "B1");
assert.eq([1, 2, 3], get(1), "B2");
@@ -31,7 +31,7 @@ t.insert({_id: 3, c: 2});
assert.eq([3, 2, 1], get(-1), "C1"); // SERVER-635
assert.eq([1, 2, 3], get(1), "C2");
-t.createIndex({c: 1});
+t.ensureIndex({c: 1});
assert.eq([3, 2, 1], get(-1), "D1");
assert.eq([1, 2, 3], get(1), "X2");
diff --git a/jstests/core/sort8.js b/jstests/core/sort8.js
index 65dc2c10fc2..75d393445a7 100644
--- a/jstests/core/sort8.js
+++ b/jstests/core/sort8.js
@@ -10,7 +10,7 @@ t.save({a: [1, 10]});
t.save({a: 5});
unindexedForward = t.find().sort({a: 1}).toArray();
unindexedReverse = t.find().sort({a: -1}).toArray();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
indexedForward = t.find().sort({a: 1}).hint({a: 1}).toArray();
indexedReverse = t.find().sort({a: -1}).hint({a: 1}).toArray();
@@ -25,7 +25,7 @@ assert.eq([1, 10], unindexedReverse[0].a);
t.dropIndexes();
unindexedForward = t.find({a: {$gte: 5}}).sort({a: 1}).toArray();
unindexedReverse = t.find({a: {$lte: 5}}).sort({a: -1}).toArray();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
indexedForward = t.find({a: {$gte: 5}}).sort({a: 1}).hint({a: 1}).toArray();
indexedReverse = t.find({a: {$lte: 5}}).sort({a: -1}).hint({a: 1}).toArray();
diff --git a/jstests/core/sort_numeric.js b/jstests/core/sort_numeric.js
index 5ff3e71a066..df4e914b87b 100644
--- a/jstests/core/sort_numeric.js
+++ b/jstests/core/sort_numeric.js
@@ -27,7 +27,7 @@ for (var pass = 0; pass < 2; pass++) {
assert(t.find({a: 3.0}).count() == 1);
assert(t.find({a: 3.0}).length() == 1);
- t.createIndex({a: 1});
+ t.ensureIndex({a: 1});
}
assert(t.validate().valid);
diff --git a/jstests/core/sortb.js b/jstests/core/sortb.js
index 7f24592e84a..34fb94951e9 100644
--- a/jstests/core/sortb.js
+++ b/jstests/core/sortb.js
@@ -8,7 +8,7 @@ load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers.
const t = db.jstests_sortb;
t.drop();
-t.createIndex({b: 1});
+t.ensureIndex({b: 1});
let i;
for (i = 0; i < 100; ++i) {
diff --git a/jstests/core/sortd.js b/jstests/core/sortd.js
index e18671005e4..87c0453cd7a 100644
--- a/jstests/core/sortd.js
+++ b/jstests/core/sortd.js
@@ -21,7 +21,7 @@ t.drop();
t.save({a: [1, 2, 3, 4, 5]});
t.save({a: 10});
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq(2, t.find({a: {$gt: 0}}).sort({a: 1}).itcount());
assert.eq(2, t.find({a: {$gt: 0}, b: null}).sort({a: 1}).itcount());
@@ -38,7 +38,7 @@ for (i = 2; i <= 9; ++i) {
for (i = 0; i < 30; ++i) {
t.save({a: 100});
}
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
checkNumSorted(10, t.find({a: {$gte: 0, $lte: 10}}).sort({a: 1}));
checkNumSorted(10, t.find({a: {$gte: 0, $lte: 10}, b: null}).sort({a: 1}));
@@ -56,7 +56,7 @@ for (i = 2; i <= 199; ++i) {
for (i = 0; i < 30; ++i) {
t.save({a: 2000});
}
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
checkNumSorted(200, t.find({a: {$gte: 0, $lte: 200}}).sort({a: 1}));
checkNumSorted(200, t.find({a: {$gte: 0, $lte: 200}, b: null}).sort({a: 1}));
@@ -69,6 +69,6 @@ t.drop();
for (i = 399; i >= 0; --i) {
t.save({a: i});
}
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
checkNumSorted(400, t.find({a: {$gte: 0, $lte: 400}, b: null}).batchSize(50).sort({a: 1}));
diff --git a/jstests/core/sortf.js b/jstests/core/sortf.js
index adb54f38b9c..6f34d80a59d 100644
--- a/jstests/core/sortf.js
+++ b/jstests/core/sortf.js
@@ -9,8 +9,8 @@
t = db.jstests_sortf;
t.drop();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
for (i = 0; i < 100; ++i) {
t.save({a: 0, b: 0});
diff --git a/jstests/core/sortg.js b/jstests/core/sortg.js
index bdf44f4db7b..64edbce53d0 100644
--- a/jstests/core/sortg.js
+++ b/jstests/core/sortg.js
@@ -47,9 +47,9 @@ noMemoryException({$natural: 1});
assert.eq(1, t.getIndexes().length);
-t.createIndex({a: 1});
-t.createIndex({b: 1});
-t.createIndex({c: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
+t.ensureIndex({c: 1});
assert.eq(4, t.getIndexes().length);
diff --git a/jstests/core/sorth.js b/jstests/core/sorth.js
index 41563caa205..4b5aa02c281 100644
--- a/jstests/core/sorth.js
+++ b/jstests/core/sorth.js
@@ -84,7 +84,7 @@ function reset(sort, index) {
t.save({a: 2, b: 0});
t.save({a: 2, b: 3});
t.save({a: 2, b: 5});
- t.createIndex(index);
+ t.ensureIndex(index);
_sort = sort;
_hint = index;
}
diff --git a/jstests/core/sorti.js b/jstests/core/sorti.js
index e30739b4867..b6518818683 100644
--- a/jstests/core/sorti.js
+++ b/jstests/core/sorti.js
@@ -20,6 +20,6 @@ function checkBOrder(query) {
checkBOrder(t.find().sort({a: 1}));
checkBOrder(t.find({}, {_id: 0, b: 1}).sort({a: 1}));
-t.createIndex({b: 1});
+t.ensureIndex({b: 1});
checkBOrder(t.find({}, {_id: 0, b: 1}).sort({a: 1}));
checkBOrder(t.find({}, {_id: 0, b: 1}).sort({a: 1}).hint({b: 1}));
diff --git a/jstests/core/sortj.js b/jstests/core/sortj.js
index a4e8dd599d4..58125c2c00c 100644
--- a/jstests/core/sortj.js
+++ b/jstests/core/sortj.js
@@ -11,7 +11,7 @@ load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers.
const t = db.jstests_sortj;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
const numShards = FixtureHelpers.numberOfShardsForCollection(t);
diff --git a/jstests/core/sortk.js b/jstests/core/sortk.js
index f1b055c2bcc..e207c8f1f78 100644
--- a/jstests/core/sortk.js
+++ b/jstests/core/sortk.js
@@ -23,7 +23,7 @@ function resetCollection() {
}
resetCollection();
-t.createIndex({a: 1, b: 1});
+t.ensureIndex({a: 1, b: 1});
function simpleQuery(extraFields, sort, hint) {
query = {a: {$in: [1, 2]}};
@@ -93,7 +93,7 @@ assert.eq(3, simpleQueryWithLimit(-3).itcount());
// The index ordering is reversed.
resetCollection();
-t.createIndex({a: 1, b: -1});
+t.ensureIndex({a: 1, b: -1});
// The sort order is consistent with the index order.
assert.eq(5, simpleQuery({}, {b: -1}, {a: 1, b: -1}).limit(-1)[0].b);
@@ -103,7 +103,7 @@ assert.eq(0, simpleQuery({}, {b: 1}, {a: 1, b: -1}).limit(-1)[0].b);
// An equality constraint precedes the $in constraint.
t.drop();
-t.createIndex({a: 1, b: 1, c: 1});
+t.ensureIndex({a: 1, b: 1, c: 1});
t.save({a: 0, b: 0, c: -1});
t.save({a: 0, b: 2, c: 1});
t.save({a: 1, b: 1, c: 1});
diff --git a/jstests/core/splitvector.js b/jstests/core/splitvector.js
index 73903a45bb9..da117c7d3ef 100644
--- a/jstests/core/splitvector.js
+++ b/jstests/core/splitvector.js
@@ -111,7 +111,7 @@ assert.eq(
// -------------------------
// Case 3: empty collection
-f.createIndex({x: 1});
+f.ensureIndex({x: 1});
assert.eq(
[],
db.runCommand({splitVector: "test.jstests_splitvector", keyPattern: {x: 1}, maxChunkSize: 1})
@@ -122,7 +122,7 @@ assert.eq(
// Case 4: uniform collection
resetCollection();
-f.createIndex({x: 1});
+f.ensureIndex({x: 1});
var case4 = function() {
// Get baseline document size
@@ -156,7 +156,7 @@ case4();
// Case 5: limit number of split points
resetCollection();
-f.createIndex({x: 1});
+f.ensureIndex({x: 1});
var case5 = function() {
// Fill collection and get split vector for 1MB maxChunkSize
@@ -180,7 +180,7 @@ case5();
// Case 6: limit number of objects in a chunk
resetCollection();
-f.createIndex({x: 1});
+f.ensureIndex({x: 1});
var case6 = function() {
// Fill collection and get split vector for 1MB maxChunkSize
@@ -205,7 +205,7 @@ case6();
// [1111111111111111,2,3)
resetCollection();
-f.createIndex({x: 1});
+f.ensureIndex({x: 1});
var case7 = function() {
// Fill collection and get split vector for 1MB maxChunkSize
@@ -227,7 +227,7 @@ case7();
// [1, 22222222222222, 3)
resetCollection();
-f.createIndex({x: 1});
+f.ensureIndex({x: 1});
var case8 = function() {
bulkInsertDocsFixedX(f, 9, filler, 1);
@@ -251,7 +251,7 @@ case8();
//
resetCollection();
-f.createIndex({x: 1});
+f.ensureIndex({x: 1});
var case9 = function() {
f.save({x: 1});
@@ -286,51 +286,51 @@ case9();
//
resetCollection();
-f.createIndex({x: 1, y: 1});
+f.ensureIndex({x: 1, y: 1});
case4();
resetCollection();
-f.createIndex({x: 1, y: -1, z: 1});
+f.ensureIndex({x: 1, y: -1, z: 1});
case4();
resetCollection();
-f.createIndex({x: 1, y: 1});
+f.ensureIndex({x: 1, y: 1});
case5();
resetCollection();
-f.createIndex({x: 1, y: -1, z: 1});
+f.ensureIndex({x: 1, y: -1, z: 1});
case5();
resetCollection();
-f.createIndex({x: 1, y: 1});
+f.ensureIndex({x: 1, y: 1});
case6();
resetCollection();
-f.createIndex({x: 1, y: -1, z: 1});
+f.ensureIndex({x: 1, y: -1, z: 1});
case6();
resetCollection();
-f.createIndex({x: 1, y: 1});
+f.ensureIndex({x: 1, y: 1});
case7();
resetCollection();
-f.createIndex({x: 1, y: -1, z: 1});
+f.ensureIndex({x: 1, y: -1, z: 1});
case7();
resetCollection();
-f.createIndex({x: 1, y: 1});
+f.ensureIndex({x: 1, y: 1});
case8();
resetCollection();
-f.createIndex({x: 1, y: -1, z: 1});
+f.ensureIndex({x: 1, y: -1, z: 1});
case8();
resetCollection();
-f.createIndex({x: 1, y: 1});
+f.ensureIndex({x: 1, y: 1});
case9();
resetCollection();
-f.createIndex({x: 1, y: -1, z: 1});
+f.ensureIndex({x: 1, y: -1, z: 1});
case9();
print("PASSED");
diff --git a/jstests/core/stages_and_hash.js b/jstests/core/stages_and_hash.js
index e5260c6c1b1..aa91f27e542 100644
--- a/jstests/core/stages_and_hash.js
+++ b/jstests/core/stages_and_hash.js
@@ -13,9 +13,9 @@ for (var i = 0; i < N; ++i) {
t.insert({foo: i, bar: N - i, baz: i});
}
-t.createIndex({foo: 1});
-t.createIndex({bar: 1});
-t.createIndex({baz: 1});
+t.ensureIndex({foo: 1});
+t.ensureIndex({bar: 1});
+t.ensureIndex({baz: 1});
// Scan foo <= 20
ixscan1 = {
diff --git a/jstests/core/stages_and_sorted.js b/jstests/core/stages_and_sorted.js
index aa4a2fa08c1..97387d84064 100644
--- a/jstests/core/stages_and_sorted.js
+++ b/jstests/core/stages_and_sorted.js
@@ -23,9 +23,9 @@ for (var i = 0; i < N; ++i) {
t.insert({baz: 12});
}
-t.createIndex({foo: 1});
-t.createIndex({bar: 1});
-t.createIndex({baz: 1});
+t.ensureIndex({foo: 1});
+t.ensureIndex({bar: 1});
+t.ensureIndex({baz: 1});
// Scan foo == 1
ixscan1 = {
diff --git a/jstests/core/stages_fetch.js b/jstests/core/stages_fetch.js
index 032cc930cf8..48d761e53e7 100644
--- a/jstests/core/stages_fetch.js
+++ b/jstests/core/stages_fetch.js
@@ -13,7 +13,7 @@ for (var i = 0; i < N; ++i) {
t.insert({foo: i, bar: N - i, baz: i});
}
-t.createIndex({foo: 1});
+t.ensureIndex({foo: 1});
// 20 <= foo <= 30
// bar == 25 (not covered, should error.)
diff --git a/jstests/core/stages_ixscan.js b/jstests/core/stages_ixscan.js
index 86184206e33..78e22e997c4 100644
--- a/jstests/core/stages_ixscan.js
+++ b/jstests/core/stages_ixscan.js
@@ -13,8 +13,8 @@ for (var i = 0; i < N; ++i) {
t.insert({foo: i, bar: N - i, baz: i});
}
-t.createIndex({foo: 1});
-t.createIndex({foo: 1, baz: 1});
+t.ensureIndex({foo: 1});
+t.ensureIndex({foo: 1, baz: 1});
// Test that stageDebug fails if neither the keyPattern nor the index name are present.
assert.commandFailed(db.runCommand({
diff --git a/jstests/core/stages_limit_skip.js b/jstests/core/stages_limit_skip.js
index 00ba7aae4f0..b2621623260 100644
--- a/jstests/core/stages_limit_skip.js
+++ b/jstests/core/stages_limit_skip.js
@@ -13,7 +13,7 @@ for (var i = 0; i < N; ++i) {
t.insert({foo: i, bar: N - i, baz: i});
}
-t.createIndex({foo: 1});
+t.ensureIndex({foo: 1});
// foo <= 20, decreasing
// Limit of 5 results.
diff --git a/jstests/core/stages_mergesort.js b/jstests/core/stages_mergesort.js
index 6679da3d5a5..c4c4125c1f3 100644
--- a/jstests/core/stages_mergesort.js
+++ b/jstests/core/stages_mergesort.js
@@ -14,8 +14,8 @@ for (var i = 0; i < N; ++i) {
t.insert({baz: 1, bar: i});
}
-t.createIndex({foo: 1, bar: 1});
-t.createIndex({baz: 1, bar: 1});
+t.ensureIndex({foo: 1, bar: 1});
+t.ensureIndex({baz: 1, bar: 1});
// foo == 1
// We would (internally) use "": MinKey and "": MaxKey for the bar index bounds.
diff --git a/jstests/core/stages_or.js b/jstests/core/stages_or.js
index d255404a21c..0fd78bdfc5c 100644
--- a/jstests/core/stages_or.js
+++ b/jstests/core/stages_or.js
@@ -13,9 +13,9 @@ for (var i = 0; i < N; ++i) {
t.insert({foo: i, bar: N - i, baz: i});
}
-t.createIndex({foo: 1});
-t.createIndex({bar: 1});
-t.createIndex({baz: 1});
+t.ensureIndex({foo: 1});
+t.ensureIndex({bar: 1});
+t.ensureIndex({baz: 1});
// baz >= 40
ixscan1 = {
diff --git a/jstests/core/stages_sort.js b/jstests/core/stages_sort.js
index 60f22c680eb..46b81662100 100644
--- a/jstests/core/stages_sort.js
+++ b/jstests/core/stages_sort.js
@@ -8,7 +8,7 @@ if (false) {
t.insert({foo: i, bar: N - i});
}
- t.createIndex({foo: 1});
+ t.ensureIndex({foo: 1});
// Foo <= 20, descending.
ixscan1 = {
diff --git a/jstests/core/stages_text.js b/jstests/core/stages_text.js
index 4b5379a0e4c..50182b04bb4 100644
--- a/jstests/core/stages_text.js
+++ b/jstests/core/stages_text.js
@@ -11,7 +11,7 @@ var collname = "stages_text";
t.save({x: "az b x"});
-t.createIndex({x: "text"});
+t.ensureIndex({x: "text"});
// We expect to retrieve 'b'
res = db.runCommand({stageDebug: {collection: collname, plan: {text: {args: {search: "b"}}}}});
diff --git a/jstests/core/type1.js b/jstests/core/type1.js
index 8066de2a5c4..aae040dee90 100644
--- a/jstests/core/type1.js
+++ b/jstests/core/type1.js
@@ -13,7 +13,7 @@ assert.eq(1, t.find({x: {$type: 1}}).count(), "A2");
assert.eq(3, t.find({x: {$type: 2}}).count(), "A3");
assert.eq(0, t.find({x: {$type: 3}}).count(), "A4");
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq(4, t.find().count(), "B1");
assert.eq(1, t.find({x: {$type: 1}}).count(), "B2");
diff --git a/jstests/core/type2.js b/jstests/core/type2.js
index d93d313d60f..9c6baa37b94 100644
--- a/jstests/core/type2.js
+++ b/jstests/core/type2.js
@@ -15,5 +15,5 @@ function test() {
}
test();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
test(); \ No newline at end of file
diff --git a/jstests/core/type3.js b/jstests/core/type3.js
index 1b57e9bb989..6c2c71e2b0c 100644
--- a/jstests/core/type3.js
+++ b/jstests/core/type3.js
@@ -8,7 +8,7 @@
t = db.jstests_type3;
t.drop();
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
// Type Object
t.save({a: {'': ''}});
diff --git a/jstests/core/uniqueness.js b/jstests/core/uniqueness.js
index af4dfb1507f..d138f59d0ae 100644
--- a/jstests/core/uniqueness.js
+++ b/jstests/core/uniqueness.js
@@ -40,7 +40,7 @@ db.jstests_uniqueness2.drop();
db.jstests_uniqueness2.insert({a: 3});
db.jstests_uniqueness2.insert({a: 3});
assert.eq(2, db.jstests_uniqueness2.count());
-res = db.jstests_uniqueness2.createIndex({a: 1}, true);
+res = db.jstests_uniqueness2.ensureIndex({a: 1}, true);
assert.commandFailed(res);
assert(res.errmsg.match(/E11000/));
@@ -49,7 +49,7 @@ db.jstests_uniqueness2.drop();
db.jstests_uniqueness2.insert({a: 3});
db.jstests_uniqueness2.insert({a: 3});
assert.eq(2, db.jstests_uniqueness2.count());
-res = db.jstests_uniqueness2.createIndex({a: 1}, {unique: true, background: true});
+res = db.jstests_uniqueness2.ensureIndex({a: 1}, {unique: true, background: true});
assert.commandFailed(res);
assert(res.errmsg.match(/E11000/));
diff --git a/jstests/core/update2.js b/jstests/core/update2.js
index 080875b50bd..558e3c7f558 100644
--- a/jstests/core/update2.js
+++ b/jstests/core/update2.js
@@ -12,7 +12,7 @@ assert.eq(6, f.findOne().a);
f.drop();
f.save({a: 4});
-f.createIndex({a: 1});
+f.ensureIndex({a: 1});
f.update({a: 4}, {$inc: {a: 2}});
assert.eq(6, f.findOne().a);
diff --git a/jstests/core/update5.js b/jstests/core/update5.js
index fafc0d72ce0..7f41096889c 100644
--- a/jstests/core/update5.js
+++ b/jstests/core/update5.js
@@ -26,7 +26,7 @@ function go(key) {
var ik = {};
for (k in key)
ik[k] = 1;
- t.createIndex(ik);
+ t.ensureIndex(ik);
t.update(key, {$inc: {n: 1}}, true);
check(4, "D");
diff --git a/jstests/core/update7.js b/jstests/core/update7.js
index 30dd79951dc..cb15f211d63 100644
--- a/jstests/core/update7.js
+++ b/jstests/core/update7.js
@@ -49,8 +49,8 @@ assert.eq("3,6", s(), "B3");
t.update({b: 3}, {$inc: {x: 1}}, false, true);
assert.eq("3,6", s(), "B4");
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
t.update({a: 1}, {$inc: {x: 1}}, false, true);
assert.eq("4,7", s(), "B5");
@@ -91,7 +91,7 @@ t.drop();
t.save({_id: 1, x: 1, a: [1, 2]});
t.save({_id: 2, x: 5, a: [2, 3]});
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.eq("1,5", s(), "D1");
t.update({a: 1}, {$inc: {x: 1}}, false, true);
@@ -134,7 +134,7 @@ t.save({x: 1});
t.save({x: 2});
t.save({x: 3});
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
assert.eq("1,2,3", s(), "F1");
t.update({x: {$gt: 0}}, {$inc: {x: 5}}, false, true);
diff --git a/jstests/core/update_arraymatch4.js b/jstests/core/update_arraymatch4.js
index 3c087e53ca5..bda7de512b8 100644
--- a/jstests/core/update_arraymatch4.js
+++ b/jstests/core/update_arraymatch4.js
@@ -17,7 +17,7 @@ x.arr[0] = "A2";
t.update({arr: "A1"}, {$set: {"arr.$": "A2"}});
assert.eq(x, t.findOne(), "A2");
-t.createIndex({arr: 1});
+t.ensureIndex({arr: 1});
x.arr[0] = "A3";
t.update({arr: "A2"}, {$set: {"arr.$": "A3"}});
assert.eq(x, t.findOne(), "A3"); // SERVER-1055
diff --git a/jstests/core/update_arraymatch5.js b/jstests/core/update_arraymatch5.js
index 4bddcb1ea26..eeca2598d1c 100644
--- a/jstests/core/update_arraymatch5.js
+++ b/jstests/core/update_arraymatch5.js
@@ -7,7 +7,7 @@ t = db.update_arraymatch5;
t.drop();
t.insert({abc: {visible: true}, testarray: [{foobar_id: 316, visible: true, xxx: 1}]});
-t.createIndex({'abc.visible': 1, 'testarray.visible': 1, 'testarray.xxx': 1});
+t.ensureIndex({'abc.visible': 1, 'testarray.visible': 1, 'testarray.xxx': 1});
assert(t.findOne({'abc.visible': true, testarray: {'$elemMatch': {visible: true, xxx: 1}}}), "A1");
assert(t.findOne({testarray: {'$elemMatch': {visible: true, xxx: 1}}}), "A2");
diff --git a/jstests/core/update_arraymatch6.js b/jstests/core/update_arraymatch6.js
index 1241753b866..ec318370561 100644
--- a/jstests/core/update_arraymatch6.js
+++ b/jstests/core/update_arraymatch6.js
@@ -16,5 +16,5 @@ function doTest() {
doTest();
t.drop();
-t.createIndex({'a.id': 1});
+t.ensureIndex({'a.id': 1});
doTest(); \ No newline at end of file
diff --git a/jstests/core/update_arraymatch7.js b/jstests/core/update_arraymatch7.js
index cded4ba56f4..4ee9ed26f7c 100644
--- a/jstests/core/update_arraymatch7.js
+++ b/jstests/core/update_arraymatch7.js
@@ -20,5 +20,5 @@ function testPositionalInc() {
testPositionalInc();
// Now check with a non multikey index.
-t.createIndex({'a.b': 1});
+t.ensureIndex({'a.b': 1});
testPositionalInc();
diff --git a/jstests/core/update_arraymatch8.js b/jstests/core/update_arraymatch8.js
index 88b9d3374e8..6340acdb2ab 100644
--- a/jstests/core/update_arraymatch8.js
+++ b/jstests/core/update_arraymatch8.js
@@ -12,7 +12,7 @@
// array.$.name
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'array.name': 1});
+t.ensureIndex({'array.name': 1});
t.insert({'array': [{'name': 'old'}]});
assert(t.findOne({'array.name': 'old'}));
t.update({'array.name': 'old'}, {$set: {'array.$.name': 'new'}});
@@ -22,7 +22,7 @@ assert(!t.findOne({'array.name': 'old'}));
// array.$ (failed in 2.2.2)
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'array.name': 1});
+t.ensureIndex({'array.name': 1});
t.insert({'array': [{'name': 'old'}]});
assert(t.findOne({'array.name': 'old'}));
t.update({'array.name': 'old'}, {$set: {'array.$': {'name': 'new'}}});
@@ -32,7 +32,7 @@ assert(!t.findOne({'array.name': 'old'}));
// array.0.name
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'array.name': 1});
+t.ensureIndex({'array.name': 1});
t.insert({'array': [{'name': 'old'}]});
assert(t.findOne({'array.name': 'old'}));
t.update({'array.name': 'old'}, {$set: {'array.0.name': 'new'}});
@@ -42,7 +42,7 @@ assert(!t.findOne({'array.name': 'old'}));
// array.0 (failed in 2.2.2)
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'array.name': 1});
+t.ensureIndex({'array.name': 1});
t.insert({'array': [{'name': 'old'}]});
assert(t.findOne({'array.name': 'old'}));
t.update({'array.name': 'old'}, {$set: {'array.0': {'name': 'new'}}});
@@ -56,7 +56,7 @@ arr = new Array();
for (var i = 0; i < 20; i++) {
arr.push({'name': 'old'});
}
-t.createIndex({'array.name': 1});
+t.ensureIndex({'array.name': 1});
t.insert({_id: 0, 'array': arr});
assert(t.findOne({'array.name': 'old'}));
t.update({_id: 0}, {$set: {'array.12.name': 'new'}});
@@ -71,7 +71,7 @@ arr = new Array();
for (var i = 0; i < 20; i++) {
arr.push({'name': 'old'});
}
-t.createIndex({'array.name': 1});
+t.ensureIndex({'array.name': 1});
t.insert({_id: 0, 'array': arr});
assert(t.findOne({'array.name': 'old'}));
t.update({_id: 0}, {$set: {'array.12': {'name': 'new'}}});
@@ -82,7 +82,7 @@ assert(t.findOne({'array.name': 'old'}));
// array.$.123a.name
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'array.123a.name': 1});
+t.ensureIndex({'array.123a.name': 1});
t.insert({'array': [{'123a': {'name': 'old'}}]});
assert(t.findOne({'array.123a.name': 'old'}));
t.update({'array.123a.name': 'old'}, {$set: {'array.$.123a.name': 'new'}});
@@ -92,7 +92,7 @@ assert(!t.findOne({'array.123a.name': 'old'}));
// array.$.123a
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'array.name': 1});
+t.ensureIndex({'array.name': 1});
t.insert({'array': [{'123a': {'name': 'old'}}]});
assert(t.findOne({'array.123a.name': 'old'}));
t.update({'array.123a.name': 'old'}, {$set: {'array.$.123a': {'name': 'new'}}});
@@ -102,7 +102,7 @@ assert(!t.findOne({'array.123a.name': 'old'}));
// array.0.123a.name
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'array.123a.name': 1});
+t.ensureIndex({'array.123a.name': 1});
t.insert({'array': [{'123a': {'name': 'old'}}]});
assert(t.findOne({'array.123a.name': 'old'}));
t.update({'array.123a.name': 'old'}, {$set: {'array.0.123a.name': 'new'}});
@@ -112,7 +112,7 @@ assert(!t.findOne({'array.123a.name': 'old'}));
// array.0.123a
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'array.name': 1});
+t.ensureIndex({'array.name': 1});
t.insert({'array': [{'123a': {'name': 'old'}}]});
assert(t.findOne({'array.123a.name': 'old'}));
t.update({'array.123a.name': 'old'}, {$set: {'array.0.123a': {'name': 'new'}}});
@@ -122,7 +122,7 @@ assert(!t.findOne({'array.123a.name': 'old'}));
// a.0.b
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'a.0.b': 1});
+t.ensureIndex({'a.0.b': 1});
t.insert({'a': [[{b: 'old'}]]});
assert(t.findOne({'a.0.0.b': 'old'}));
assert(t.findOne({'a.0.b': 'old'}));
@@ -133,7 +133,7 @@ assert(!t.findOne({'a.0.b': 'old'}));
// a.0.b.c
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'a.0.b.c': 1});
+t.ensureIndex({'a.0.b.c': 1});
t.insert({'a': [{b: [{c: 'old'}]}]});
assert(t.findOne({'a.0.b.0.c': 'old'}));
assert(t.findOne({'a.b.0.c': 'old'}));
@@ -146,7 +146,7 @@ assert(!t.findOne({'a.0.b.c': 'old'}));
// a.b.$ref
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'a.b.$ref': 1});
+t.ensureIndex({'a.b.$ref': 1});
t.insert({'a': [{'b': {'$ref': 'old', '$id': 0}}]});
assert(t.findOne({'a.b.$ref': 'old'}));
assert(t.findOne({'a.0.b.$ref': 'old'}));
@@ -157,8 +157,8 @@ assert(!t.findOne({'a.b.$ref': 'old'}));
// a.b and a-b
t = db.jstests_update_arraymatch8;
t.drop();
-t.createIndex({'a.b': 1});
-t.createIndex({'a-b': 1});
+t.ensureIndex({'a.b': 1});
+t.ensureIndex({'a-b': 1});
t.insert({'a': {'b': 'old'}});
assert(t.findOne({'a.b': 'old'}));
t.update({}, {$set: {'a': {'b': 'new'}}});
diff --git a/jstests/core/update_multi3.js b/jstests/core/update_multi3.js
index c8a1fa3b11d..0077bfefead 100644
--- a/jstests/core/update_multi3.js
+++ b/jstests/core/update_multi3.js
@@ -6,7 +6,7 @@ function test(useIndex) {
t.drop();
if (useIndex)
- t.createIndex({k: 1});
+ t.ensureIndex({k: 1});
for (i = 0; i < 10; i++) {
t.save({_id: i, k: 'x', a: []});
diff --git a/jstests/core/update_multi4.js b/jstests/core/update_multi4.js
index 38fd75358f0..d2030c5dc4b 100644
--- a/jstests/core/update_multi4.js
+++ b/jstests/core/update_multi4.js
@@ -7,7 +7,7 @@ for (i = 0; i < 1000; i++) {
t.insert({_id: i, k: i % 12, v: "v" + i % 12});
}
-t.createIndex({k: 1});
+t.ensureIndex({k: 1});
assert.eq(84, t.count({k: 2, v: "v2"}), "A0");
diff --git a/jstests/core/update_setOnInsert.js b/jstests/core/update_setOnInsert.js
index 9457c69f325..430f23ce6dd 100644
--- a/jstests/core/update_setOnInsert.js
+++ b/jstests/core/update_setOnInsert.js
@@ -5,7 +5,7 @@ var res;
function dotest(useIndex) {
t.drop();
if (useIndex) {
- t.createIndex({a: 1});
+ t.ensureIndex({a: 1});
}
t.update({_id: 5}, {$inc: {x: 2}, $setOnInsert: {a: 3}}, true);
diff --git a/jstests/core/useindexonobjgtlt.js b/jstests/core/useindexonobjgtlt.js
index 7b393de7c2f..4d2368f316f 100644
--- a/jstests/core/useindexonobjgtlt.js
+++ b/jstests/core/useindexonobjgtlt.js
@@ -3,7 +3,7 @@
t = db.factories;
t.drop();
t.insert({name: "xyz", metro: {city: "New York", state: "NY"}});
-t.createIndex({metro: 1});
+t.ensureIndex({metro: 1});
assert(db.factories.find().count());
diff --git a/jstests/gle/create_index_gle.js b/jstests/gle/create_index_gle.js
index 11e7186817e..8a10e5a2e9f 100644
--- a/jstests/gle/create_index_gle.js
+++ b/jstests/gle/create_index_gle.js
@@ -38,7 +38,7 @@ var testDB2 = secConn.getDB('test');
testDB.user.insert({x: 1});
-testDB.user.createIndex({x: 1});
+testDB.user.ensureIndex({x: 1});
assert.gleOK(testDB.runCommand({getLastError: 1, w: 2}));
replTest.awaitReplication();
diff --git a/jstests/libs/geo_near_random.js b/jstests/libs/geo_near_random.js
index c45cec7e813..193809cd5db 100644
--- a/jstests/libs/geo_near_random.js
+++ b/jstests/libs/geo_near_random.js
@@ -40,9 +40,9 @@ GeoNearRandomTest.prototype.insertPts = function(nPts, indexBounds, scale, skipI
if (!skipIndex) {
if (!indexBounds)
- this.t.createIndex({loc: '2d'});
+ this.t.ensureIndex({loc: '2d'});
else
- this.t.createIndex({loc: '2d'}, indexBounds);
+ this.t.ensureIndex({loc: '2d'}, indexBounds);
}
};
diff --git a/jstests/libs/write_concern_util.js b/jstests/libs/write_concern_util.js
index b1118a095c1..68f01cb9e87 100644
--- a/jstests/libs/write_concern_util.js
+++ b/jstests/libs/write_concern_util.js
@@ -8,7 +8,7 @@ load("jstests/libs/fail_point_util.js");
function shardCollectionWithChunks(st, coll, numDocs) {
var _db = coll.getDB();
var numberDoc = numDocs || 20;
- coll.createIndex({x: 1}, {unique: true});
+ coll.ensureIndex({x: 1}, {unique: true});
st.ensurePrimaryShard(_db.toString(), st.shard0.shardName);
st.shardColl(
coll.getName(), {x: 1}, {x: numberDoc / 2}, {x: numberDoc / 2}, _db.toString(), true);
diff --git a/jstests/multiVersion/libs/data_generators.js b/jstests/multiVersion/libs/data_generators.js
index a46fbe8439a..4a30ca2e463 100644
--- a/jstests/multiVersion/libs/data_generators.js
+++ b/jstests/multiVersion/libs/data_generators.js
@@ -350,7 +350,7 @@ function DataGenerator() {
// var nextIndexDocument = generator.next();
// var nextIndexSpec = nextIndexDocument["spec"];
// var nextIndexOptions = nextIndexDocument["options"];
-// db.createIndex(nextIndexSpec, nextIndexOptions);
+// db.ensureIndex(nextIndexSpec, nextIndexOptions);
// }
//
function IndexDataGenerator(options) {
diff --git a/jstests/multiVersion/libs/verify_collection_data.js b/jstests/multiVersion/libs/verify_collection_data.js
index ea2ef2f3f35..10b26534ccc 100644
--- a/jstests/multiVersion/libs/verify_collection_data.js
+++ b/jstests/multiVersion/libs/verify_collection_data.js
@@ -35,10 +35,10 @@ createCollectionWithData = function(db, collectionName, dataGenerator) {
var numIndexes = 0;
while (dataGenerator.indexes.hasNext()) {
var nextIndex = dataGenerator.indexes.next();
- print("collection.createIndex(" + JSON.stringify(nextIndex.spec) + ", " +
+ print("collection.ensureIndex(" + JSON.stringify(nextIndex.spec) + ", " +
JSON.stringify(nextIndex.options) + ");");
- var createIndexResult = collection.createIndex(nextIndex.spec, nextIndex.options);
- assert.commandWorked(createIndexResult);
+ var ensureIndexResult = collection.ensureIndex(nextIndex.spec, nextIndex.options);
+ assert.commandWorked(ensureIndexResult);
numIndexes++;
}
diff --git a/jstests/noPassthrough/current_op_reports_validation_io.js b/jstests/noPassthrough/current_op_reports_validation_io.js
index b2b80379bce..3eecda706ee 100644
--- a/jstests/noPassthrough/current_op_reports_validation_io.js
+++ b/jstests/noPassthrough/current_op_reports_validation_io.js
@@ -18,7 +18,7 @@ let coll = db.getCollection(collName);
coll.drop();
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
for (let i = 0; i < 5; i++) {
assert.commandWorked(coll.insert({a: i}));
}
diff --git a/jstests/noPassthrough/document_count_functions.js b/jstests/noPassthrough/document_count_functions.js
index 1cb21f2bf18..207a6a65efa 100644
--- a/jstests/noPassthrough/document_count_functions.js
+++ b/jstests/noPassthrough/document_count_functions.js
@@ -39,7 +39,7 @@ assert.eq(3, coll.countDocuments({i: 1}, {limit: 3}));
// that we will have 2 left.
assert.eq(2, coll.countDocuments({i: 1}, {skip: 2}));
-assert.commandWorked(coll.createIndex({i: 1}));
+assert.commandWorked(coll.ensureIndex({i: 1}));
// Aggregate stage case: Add an option that gets added as an aggregation argument.
assert.eq(4, coll.countDocuments({i: 1}, {hint: {i: 1}}));
diff --git a/jstests/noPassthrough/filemd5_kill_during_yield.js b/jstests/noPassthrough/filemd5_kill_during_yield.js
index 3a9973cc116..c13fd9ab896 100644
--- a/jstests/noPassthrough/filemd5_kill_during_yield.js
+++ b/jstests/noPassthrough/filemd5_kill_during_yield.js
@@ -12,7 +12,7 @@ const db = conn.getDB("test");
db.fs.chunks.drop();
assert.commandWorked(db.fs.chunks.insert({files_id: 1, n: 0, data: new BinData(0, "64string")}));
assert.commandWorked(db.fs.chunks.insert({files_id: 1, n: 1, data: new BinData(0, "test")}));
-db.fs.chunks.createIndex({files_id: 1, n: 1});
+db.fs.chunks.ensureIndex({files_id: 1, n: 1});
const kFailPointName = "waitInFilemd5DuringManualYield";
assert.commandWorked(db.adminCommand({configureFailPoint: kFailPointName, mode: "alwaysOn"}));
diff --git a/jstests/noPassthrough/geo_full.js b/jstests/noPassthrough/geo_full.js
index e2cf2b03491..8d7fb12b73f 100644
--- a/jstests/noPassthrough/geo_full.js
+++ b/jstests/noPassthrough/geo_full.js
@@ -390,11 +390,11 @@ for (var test = 0; test < numTests; test++) {
var indexDoc = {"locs.loc": "2d"};
randIndexAdditions(indexDoc);
- // "earth" is used to drive test setup and not a valid createIndex option or required at
- // this point. It must be removed before calling createIndex().
+ // "earth" is used to drive test setup and not a valid createIndexes option or required at
+ // this point. It must be removed before calling ensureIndexes().
delete env.earth;
- assert.commandWorked(t.createIndex(indexDoc, env));
+ assert.commandWorked(t.ensureIndex(indexDoc, env));
assert.isnull(db.getLastError());
var padding = "x";
diff --git a/jstests/noPassthrough/geo_mnypts_plus_fields.js b/jstests/noPassthrough/geo_mnypts_plus_fields.js
index f1782de5a16..467c46e3698 100644
--- a/jstests/noPassthrough/geo_mnypts_plus_fields.js
+++ b/jstests/noPassthrough/geo_mnypts_plus_fields.js
@@ -57,7 +57,7 @@ for (var fields = 1; fields < maxFields; fields++) {
queryFields["field" + j] = field;
}
- coll.createIndex({loc: "2d"});
+ coll.ensureIndex({loc: "2d"});
// Check that quarter of points in each quadrant
for (var i = 0; i < 4; i++) {
diff --git a/jstests/noPassthrough/index_partial_no_explain_cmds.js b/jstests/noPassthrough/index_partial_no_explain_cmds.js
index 122ae1fade8..2ad426d9d23 100644
--- a/jstests/noPassthrough/index_partial_no_explain_cmds.js
+++ b/jstests/noPassthrough/index_partial_no_explain_cmds.js
@@ -11,7 +11,7 @@ var ret;
coll.drop();
db.getCollection("mrOutput").drop();
-assert.commandWorked(coll.createIndex({x: 1}, {partialFilterExpression: {a: 1}}));
+assert.commandWorked(coll.ensureIndex({x: 1}, {partialFilterExpression: {a: 1}}));
assert.commandWorked(coll.insert({_id: 1, x: 5, a: 2})); // Not in index.
assert.commandWorked(coll.insert({_id: 2, x: 6, a: 1})); // In index.
diff --git a/jstests/noPassthrough/indexbg1.js b/jstests/noPassthrough/indexbg1.js
index 24b93699399..c2bdf180be3 100644
--- a/jstests/noPassthrough/indexbg1.js
+++ b/jstests/noPassthrough/indexbg1.js
@@ -56,7 +56,7 @@ while (1) { // if indexing finishes before we can run checks, try indexing w/ m
assert.commandWorked(bulk.execute());
assert.eq(size, t.count());
- bgIndexBuildPid = doParallel(fullName + ".createIndex( {i:1}, {background:true} )");
+ bgIndexBuildPid = doParallel(fullName + ".ensureIndex( {i:1}, {background:true} )");
try {
// wait for indexing to start
print("wait for indexing to start");
diff --git a/jstests/noPassthrough/indexbg2.js b/jstests/noPassthrough/indexbg2.js
index 947c8156493..e4e30f69813 100644
--- a/jstests/noPassthrough/indexbg2.js
+++ b/jstests/noPassthrough/indexbg2.js
@@ -30,7 +30,7 @@ let doParallel = function(work) {
let indexBuild = function() {
let fullName = "db." + baseName;
- return doParallel(fullName + ".createIndex( {i:1}, {background:true, unique:true} )");
+ return doParallel(fullName + ".ensureIndex( {i:1}, {background:true, unique:true} )");
};
let doneParallel = function() {
diff --git a/jstests/noPassthrough/indexbg_drop.js b/jstests/noPassthrough/indexbg_drop.js
index 8b290849965..c7ef4245fc5 100644
--- a/jstests/noPassthrough/indexbg_drop.js
+++ b/jstests/noPassthrough/indexbg_drop.js
@@ -52,8 +52,8 @@ assert.commandWorked(
jsTest.log("Starting background indexing for test of: " + tojson(dc));
// Add another index to be sure the drop command works.
-primaryDB.getCollection(collection).createIndex({b: 1});
-primaryDB.getCollection(collection).createIndex({i: 1}, {background: true});
+primaryDB.getCollection(collection).ensureIndex({b: 1});
+primaryDB.getCollection(collection).ensureIndex({i: 1}, {background: true});
// Make sure the index build has started on the secondary.
IndexBuildTest.waitForIndexBuildToStart(secondDB);
diff --git a/jstests/noPassthrough/libs/backup_restore.js b/jstests/noPassthrough/libs/backup_restore.js
index 5bc83d693d5..b882d2d0439 100644
--- a/jstests/noPassthrough/libs/backup_restore.js
+++ b/jstests/noPassthrough/libs/backup_restore.js
@@ -50,7 +50,7 @@ var BackupRestoreTest = function(options) {
let iteration = 0;
var coll = db.getSiblingDB(dbName).getCollection(collectionName);
- coll.createIndex({x: 1});
+ coll.ensureIndex({x: 1});
var largeValue = new Array(1024).join('L');
diff --git a/jstests/noPassthrough/lookup_with_limit_sharded.js b/jstests/noPassthrough/lookup_with_limit_sharded.js
index ef379ec073e..e6ee126a03f 100644
--- a/jstests/noPassthrough/lookup_with_limit_sharded.js
+++ b/jstests/noPassthrough/lookup_with_limit_sharded.js
@@ -98,7 +98,7 @@ const explain = coll.explain().aggregate(topKSortPipeline);
assert.eq(explain.stages[0].$cursor.queryPlanner.winningPlan.limitAmount, 5, explain);
// Tests on a sharded collection.
-coll.createIndex({x: 1});
+coll.ensureIndex({x: 1});
st.shardColl(coll, {x: 1}, {x: 1}, {x: 1}, db, true);
checkShardedResults(lookupPipeline, 2);
diff --git a/jstests/noPassthrough/ttl_capped.js b/jstests/noPassthrough/ttl_capped.js
index f22329d8ca3..662e5781e03 100644
--- a/jstests/noPassthrough/ttl_capped.js
+++ b/jstests/noPassthrough/ttl_capped.js
@@ -38,7 +38,7 @@ for (var i = 0; i < numCollectionsToCreate; i++) {
}
// Create a TTL index on the 'date' field of the collection.
- var res = testDB[collName].createIndex({date: 1}, {expireAfterSeconds: expireAfterSeconds});
+ var res = testDB[collName].ensureIndex({date: 1}, {expireAfterSeconds: expireAfterSeconds});
assert.commandWorked(res);
// Insert a single document with a 'date' field that is already expired according to the
diff --git a/jstests/noPassthrough/ttl_hidden_index.js b/jstests/noPassthrough/ttl_hidden_index.js
index b64f4822638..80c783dad33 100644
--- a/jstests/noPassthrough/ttl_hidden_index.js
+++ b/jstests/noPassthrough/ttl_hidden_index.js
@@ -6,7 +6,7 @@ let coll = runner.getDB("test").ttl_hiddenl_index;
coll.drop();
// Create TTL index.
-assert.commandWorked(coll.createIndex({x: 1}, {expireAfterSeconds: 0}));
+assert.commandWorked(coll.ensureIndex({x: 1}, {expireAfterSeconds: 0}));
let now = new Date();
assert.commandWorked(coll.hideIndex("x_1"));
diff --git a/jstests/noPassthrough/ttl_monitor_does_not_unregister_index_during_collection_creation.js b/jstests/noPassthrough/ttl_monitor_does_not_unregister_index_during_collection_creation.js
index 9758aec62b3..c96b2f8d642 100644
--- a/jstests/noPassthrough/ttl_monitor_does_not_unregister_index_during_collection_creation.js
+++ b/jstests/noPassthrough/ttl_monitor_does_not_unregister_index_during_collection_creation.js
@@ -25,10 +25,10 @@ const failPoint = "hangTTLCollectionCacheAfterRegisteringInfo";
assert.commandWorked(db.adminCommand({configureFailPoint: failPoint, mode: "alwaysOn"}));
// Create an index on a non-existent collection. This will implicitly create the collection.
-let awaitcreateIndex = startParallelShell(() => {
+let awaitEnsureIndex = startParallelShell(() => {
const testDB = db.getSiblingDB(TestData.dbName);
assert.commandWorked(
- testDB.getCollection(TestData.collName).createIndex({x: 1}, {expireAfterSeconds: 0}));
+ testDB.getCollection(TestData.collName).ensureIndex({x: 1}, {expireAfterSeconds: 0}));
}, db.getMongo().port);
// Wait for the TTL monitor to run and register the index in the TTL collection cache.
@@ -43,7 +43,7 @@ assert.soon(function() {
// Finish the index build.
assert.commandWorked(db.adminCommand({configureFailPoint: failPoint, mode: "off"}));
-awaitcreateIndex();
+awaitEnsureIndex();
// Insert documents, which should expire immediately and be removed on the next TTL pass.
const now = new Date();
diff --git a/jstests/noPassthrough/ttl_partial_index.js b/jstests/noPassthrough/ttl_partial_index.js
index 977eb4aef4c..61cc5e6aff1 100644
--- a/jstests/noPassthrough/ttl_partial_index.js
+++ b/jstests/noPassthrough/ttl_partial_index.js
@@ -8,7 +8,7 @@ var coll = runner.getDB("test").ttl_partial_index;
coll.drop();
// Create TTL partial index.
-assert.commandWorked(coll.createIndex(
+assert.commandWorked(coll.ensureIndex(
{x: 1}, {expireAfterSeconds: 0, partialFilterExpression: {z: {$exists: true}}}));
var now = new Date();
diff --git a/jstests/noPassthrough/ttl_resharding_collection.js b/jstests/noPassthrough/ttl_resharding_collection.js
index 648d1a9b056..715c2801331 100644
--- a/jstests/noPassthrough/ttl_resharding_collection.js
+++ b/jstests/noPassthrough/ttl_resharding_collection.js
@@ -7,7 +7,7 @@ const collName = "system.resharding.mycoll";
const coll = runner.getDB(jsTestName())[collName];
coll.drop();
-assert.commandWorked(coll.createIndex({x: 1}, {expireAfterSeconds: 0}));
+assert.commandWorked(coll.ensureIndex({x: 1}, {expireAfterSeconds: 0}));
const now = new Date();
assert.commandWorked(coll.insert({x: now}));
diff --git a/jstests/noPassthrough/update_server-5552.js b/jstests/noPassthrough/update_server-5552.js
index 4af4491b999..876f9688c6f 100644
--- a/jstests/noPassthrough/update_server-5552.js
+++ b/jstests/noPassthrough/update_server-5552.js
@@ -17,7 +17,7 @@ for (let i = 0; i < N; i++) {
assert.commandWorked(bulk.execute());
const join = startParallelShell(
- "while( db.foo.findOne( { _id : 0 } ).x == 1 ); db.foo.createIndex( { x : 1 } );");
+ "while( db.foo.findOne( { _id : 0 } ).x == 1 ); db.foo.ensureIndex( { x : 1 } );");
t.update({
$where: function() {
diff --git a/jstests/noPassthroughWithMongod/apply_ops_errors.js b/jstests/noPassthroughWithMongod/apply_ops_errors.js
index 2e2fb2d6069..0cf4a789718 100644
--- a/jstests/noPassthroughWithMongod/apply_ops_errors.js
+++ b/jstests/noPassthroughWithMongod/apply_ops_errors.js
@@ -19,7 +19,7 @@ coll.drop();
// Scenario 1: only one operation
assert.eq(0, coll.find().count(), "test collection not empty");
-coll.createIndex({x: 1}, {unique: true});
+coll.ensureIndex({x: 1}, {unique: true});
coll.insert({_id: 1, x: "init"});
var res = db.runCommand({
@@ -38,7 +38,7 @@ coll.drop();
// Scenario 2: Three operations, first two should run, second should fail.
assert.eq(0, coll.find().count(), "test collection not empty");
-coll.createIndex({x: 1}, {unique: true});
+coll.ensureIndex({x: 1}, {unique: true});
coll.insert({_id: 1, x: "init"});
var res = db.runCommand({
diff --git a/jstests/noPassthroughWithMongod/background.js b/jstests/noPassthroughWithMongod/background.js
index a6fe673a376..ef591fa5114 100644
--- a/jstests/noPassthroughWithMongod/background.js
+++ b/jstests/noPassthroughWithMongod/background.js
@@ -18,7 +18,7 @@ for (var i = 0; i < 100000; i++) {
}
// start bg indexing
-a.bg1.createIndex({i: 1}, {name: "i_1", background: true});
+a.bg1.ensureIndex({i: 1}, {name: "i_1", background: true});
// add more data
bulk = t.initializeUnorderedBulkOp();
diff --git a/jstests/noPassthroughWithMongod/bulk_api_limits.js b/jstests/noPassthroughWithMongod/bulk_api_limits.js
index 91b56f80951..3dada22c519 100644
--- a/jstests/noPassthroughWithMongod/bulk_api_limits.js
+++ b/jstests/noPassthroughWithMongod/bulk_api_limits.js
@@ -17,7 +17,7 @@ var executeTestsUnordered = function() {
// Create unique index
coll.dropIndexes();
coll.remove({});
- coll.createIndex({a: 1}, {unique: true});
+ coll.ensureIndex({a: 1}, {unique: true});
/**
* Fail during batch construction due to single document > maxBSONSize
diff --git a/jstests/noPassthroughWithMongod/capped4.js b/jstests/noPassthroughWithMongod/capped4.js
index c659ff65935..bfa92cef26d 100644
--- a/jstests/noPassthroughWithMongod/capped4.js
+++ b/jstests/noPassthroughWithMongod/capped4.js
@@ -3,7 +3,7 @@ t = db.jstests_capped4;
t.drop();
db.createCollection("jstests_capped4", {size: 1000, capped: true});
-t.createIndex({i: 1});
+t.ensureIndex({i: 1});
for (i = 0; i < 20; ++i) {
t.save({i: i});
}
diff --git a/jstests/noPassthroughWithMongod/dup_bgindex.js b/jstests/noPassthroughWithMongod/dup_bgindex.js
index dd62117cf9f..02ac4bf7870 100644
--- a/jstests/noPassthroughWithMongod/dup_bgindex.js
+++ b/jstests/noPassthroughWithMongod/dup_bgindex.js
@@ -7,10 +7,10 @@ for (var i = 0; i < 10000; i++) {
docs.push({name: "foo", z: {a: 17, b: 4}, i: i});
}
assert.commandWorked(t.insert(docs));
-var cmd = "assert.commandWorked(db.duplIndexTest.createIndex( { i : 1 }, {background:true} ));";
+var cmd = "assert.commandWorked(db.duplIndexTest.ensureIndex( { i : 1 }, {background:true} ));";
var join1 = startParallelShell(cmd);
var join2 = startParallelShell(cmd);
-assert.commandWorked(t.createIndex({i: 1}, {background: true}));
+assert.commandWorked(t.ensureIndex({i: 1}, {background: true}));
assert.eq(1, t.find({i: 1}).count(), "Should find only one doc");
assert.commandWorked(t.dropIndex({i: 1}));
assert.eq(1, t.find({i: 1}).count(), "Should find only one doc");
diff --git a/jstests/noPassthroughWithMongod/explain1.js b/jstests/noPassthroughWithMongod/explain1.js
index 1156a5b86ed..7b37ade1ece 100644
--- a/jstests/noPassthroughWithMongod/explain1.js
+++ b/jstests/noPassthroughWithMongod/explain1.js
@@ -8,7 +8,7 @@ s1 = startParallelShell(function() {
t = db.jstests_slowNightly_explain1;
for (var i = 0; i < 80; ++i) {
t.drop();
- t.createIndex({x: 1});
+ t.ensureIndex({x: 1});
for (var j = 0; j < 1000; ++j) {
t.save({x: j, y: 1});
}
diff --git a/jstests/noPassthroughWithMongod/explain2.js b/jstests/noPassthroughWithMongod/explain2.js
index 0720091e4a4..3766c3a0e93 100644
--- a/jstests/noPassthroughWithMongod/explain2.js
+++ b/jstests/noPassthroughWithMongod/explain2.js
@@ -8,7 +8,7 @@ t.drop();
db.createCollection(collName, {capped: true, size: 100000});
t = db[collName];
-t.createIndex({x: 1});
+t.ensureIndex({x: 1});
a = startParallelShell('for( i = 0; i < 50000; ++i ) { db.' + collName + '.insert( {x:i,y:1} ); }');
diff --git a/jstests/noPassthroughWithMongod/explain3.js b/jstests/noPassthroughWithMongod/explain3.js
index 6d35949d273..d402b610d96 100644
--- a/jstests/noPassthroughWithMongod/explain3.js
+++ b/jstests/noPassthroughWithMongod/explain3.js
@@ -8,7 +8,7 @@ s1 = startParallelShell(function() {
t = db.jstests_slowNightly_explain3;
for (var i = 0; i < 80; ++i) {
t.drop();
- t.createIndex({x: 1});
+ t.ensureIndex({x: 1});
for (var j = 0; j < 1000; ++j) {
t.save({x: j, y: 1});
}
diff --git a/jstests/noPassthroughWithMongod/external_sort_text_agg.js b/jstests/noPassthroughWithMongod/external_sort_text_agg.js
index 583aff8601b..089432b88d0 100644
--- a/jstests/noPassthroughWithMongod/external_sort_text_agg.js
+++ b/jstests/noPassthroughWithMongod/external_sort_text_agg.js
@@ -1,7 +1,7 @@
// Ensure text search metadata is not lost in an external sort
var t = db.external_sort_text_agg;
t.drop();
-t.createIndex({text: "text"});
+t.ensureIndex({text: "text"});
for (i = 0; i < 100; i++) {
t.insert({_id: i, text: Array(210000).join("asdf ")});
// string over 1MB to hit the 100MB threshold for external sort
diff --git a/jstests/noPassthroughWithMongod/geo_axis_aligned.js b/jstests/noPassthroughWithMongod/geo_axis_aligned.js
index 877954b0f2a..0849b6b7acc 100644
--- a/jstests/noPassthroughWithMongod/geo_axis_aligned.js
+++ b/jstests/noPassthroughWithMongod/geo_axis_aligned.js
@@ -62,9 +62,9 @@ for (var b = 0; b < bits.length; b++) {
{"_id": 9, "loc": {"x": center[j][0] + radius[i], "y": center[j][1] - radius[i]}});
var res =
- t.createIndex({loc: "2d"}, {max: bound[j][1], min: bound[j][0], bits: bits[b]});
+ t.ensureIndex({loc: "2d"}, {max: bound[j][1], min: bound[j][0], bits: bits[b]});
- // createIndex fails when this iteration inserted coordinates that are out of bounds.
+ // ensureIndex fails when this iteration inserted coordinates that are out of bounds.
// These are invalid cases, so we skip them.
if (!res.ok)
continue;
diff --git a/jstests/noPassthroughWithMongod/geo_mnypts.js b/jstests/noPassthroughWithMongod/geo_mnypts.js
index 7566c479588..d3ae714b69b 100644
--- a/jstests/noPassthroughWithMongod/geo_mnypts.js
+++ b/jstests/noPassthroughWithMongod/geo_mnypts.js
@@ -13,7 +13,7 @@ for (var i = 0; i < totalPts; i++) {
}
assert.commandWorked(bulk.execute());
-coll.createIndex({loc: "2d"});
+coll.ensureIndex({loc: "2d"});
// Check that quarter of points in each quadrant
for (var i = 0; i < 4; i++) {
diff --git a/jstests/noPassthroughWithMongod/geo_polygon.js b/jstests/noPassthroughWithMongod/geo_polygon.js
index 28110591d64..d0085fa1f92 100644
--- a/jstests/noPassthroughWithMongod/geo_polygon.js
+++ b/jstests/noPassthroughWithMongod/geo_polygon.js
@@ -20,7 +20,7 @@ var numTests = 31;
var start = (TestData.undoRecorderPath ? 20 : 0);
for (var n = start; n < numTests; n++) {
t.dropIndexes();
- t.createIndex({loc: "2d"}, {bits: 2 + n});
+ t.ensureIndex({loc: "2d"}, {bits: 2 + n});
assert.between(9 - 2,
t.find({loc: {"$within": {"$polygon": [[0, 0], [1, 1], [0, 2]]}}}).count(),
diff --git a/jstests/noPassthroughWithMongod/huge_multikey_index.js b/jstests/noPassthroughWithMongod/huge_multikey_index.js
index 195a85e9b5f..9c19c0d00a1 100644
--- a/jstests/noPassthroughWithMongod/huge_multikey_index.js
+++ b/jstests/noPassthroughWithMongod/huge_multikey_index.js
@@ -13,9 +13,9 @@ function doit() {
t.insert({a: arr});
- // t.createIndex({a:1}, {background:true}) // always worked
+ // t.ensureIndex({a:1}, {background:true}) // always worked
- t.createIndex({a: 1}); // used to fail server with out of fds error
+ t.ensureIndex({a: 1}); // used to fail server with out of fds error
}
doit();
diff --git a/jstests/noPassthroughWithMongod/index_check10.js b/jstests/noPassthroughWithMongod/index_check10.js
index f355ace6bb8..e0786a4e539 100644
--- a/jstests/noPassthroughWithMongod/index_check10.js
+++ b/jstests/noPassthroughWithMongod/index_check10.js
@@ -108,7 +108,7 @@ function doIt() {
}
assert.commandWorked(bulk.execute());
- t.createIndex(idx);
+ t.ensureIndex(idx);
check();
bulk = t.initializeUnorderedBulkOp();
diff --git a/jstests/noPassthroughWithMongod/index_check9.js b/jstests/noPassthroughWithMongod/index_check9.js
index 3e082cb1a3f..8a693604bb8 100644
--- a/jstests/noPassthroughWithMongod/index_check9.js
+++ b/jstests/noPassthroughWithMongod/index_check9.js
@@ -25,7 +25,7 @@ function doIt() {
alphas.push(Random.rand() > 0.5);
}
- t.createIndex(idx);
+ t.ensureIndex(idx);
function obj() {
var ret = {};
diff --git a/jstests/noPassthroughWithMongod/indexbg_interrupts.js b/jstests/noPassthroughWithMongod/indexbg_interrupts.js
index b468596bd14..19055c16cf5 100644
--- a/jstests/noPassthroughWithMongod/indexbg_interrupts.js
+++ b/jstests/noPassthroughWithMongod/indexbg_interrupts.js
@@ -78,7 +78,7 @@ for (var idx = 0; idx < dropAction.length; idx++) {
assert.commandWorked(bulk.execute());
jsTest.log("Starting background indexing for test of: " + JSON.stringify(dc));
- primaryDB.getCollection(collection).createIndex({i: 1}, {background: true});
+ primaryDB.getCollection(collection).ensureIndex({i: 1}, {background: true});
assert.eq(2, primaryDB.getCollection(collection).getIndexes().length);
// Wait for the secondary to get the index entry
diff --git a/jstests/noPassthroughWithMongod/recstore.js b/jstests/noPassthroughWithMongod/recstore.js
index cae767b0637..fdb41af568b 100644
--- a/jstests/noPassthroughWithMongod/recstore.js
+++ b/jstests/noPassthroughWithMongod/recstore.js
@@ -10,13 +10,13 @@ t.drop();
t.save({z: 3});
t.save({z: 2});
-t.createIndex({z: 1});
-t.createIndex({q: 1});
+t.ensureIndex({z: 1});
+t.ensureIndex({q: 1});
assert(t.find().sort({z: 1})[0].z == 2);
t.dropIndexes();
assert(t.find().sort({z: 1})[0].z == 2);
-t.createIndex({z: 1});
-t.createIndex({q: 1});
+t.ensureIndex({z: 1});
+t.ensureIndex({q: 1});
diff --git a/jstests/noPassthroughWithMongod/renameWithWCE.js b/jstests/noPassthroughWithMongod/renameWithWCE.js
index db932e4621a..0c232ec0b37 100644
--- a/jstests/noPassthroughWithMongod/renameWithWCE.js
+++ b/jstests/noPassthroughWithMongod/renameWithWCE.js
@@ -23,8 +23,8 @@ b.drop();
a.save({a: 1});
a.save({a: 2});
a.save({a: 3});
-a.createIndex({a: 1});
-a.createIndex({b: 1});
+a.ensureIndex({a: 1});
+a.ensureIndex({b: 1});
assert.commandWorked(admin.runCommand({renameCollection: "db_a.rename7", to: "db_b.rename7"}));
diff --git a/jstests/noPassthroughWithMongod/temp_namespace.js b/jstests/noPassthroughWithMongod/temp_namespace.js
index 1f4438d5b96..257874d5966 100644
--- a/jstests/noPassthroughWithMongod/temp_namespace.js
+++ b/jstests/noPassthroughWithMongod/temp_namespace.js
@@ -10,10 +10,10 @@ d = conn.getDB('test');
assert.commandWorked(d.runCommand({
applyOps: [{op: "c", ns: d.getName() + ".$cmd", o: {create: testname + 'temp1', temp: true}}]
}));
-d[testname + 'temp1'].createIndex({x: 1});
+d[testname + 'temp1'].ensureIndex({x: 1});
assert.commandWorked(d.runCommand(
{applyOps: [{op: "c", ns: d.getName() + ".$cmd", o: {create: testname + 'temp2', temp: 1}}]}));
-d[testname + 'temp2'].createIndex({x: 1});
+d[testname + 'temp2'].ensureIndex({x: 1});
assert.commandWorked(d.runCommand({
applyOps: [{op: "c", ns: d.getName() + ".$cmd", o: {create: testname + 'keep1', temp: false}}]
}));
diff --git a/jstests/noPassthroughWithMongod/ttl1.js b/jstests/noPassthroughWithMongod/ttl1.js
index 94738104d73..2c1b0d65cbf 100644
--- a/jstests/noPassthroughWithMongod/ttl1.js
+++ b/jstests/noPassthroughWithMongod/ttl1.js
@@ -33,7 +33,7 @@ sleep(70 * 1000);
assert.eq(t.count(), 30);
// Part 2
-t.createIndex({x: 1}, {expireAfterSeconds: 20000});
+t.ensureIndex({x: 1}, {expireAfterSeconds: 20000});
assert.soon(function() {
return t.count() < 30;
@@ -49,7 +49,7 @@ assert.lte(18, db.serverStatus().metrics.ttl.deletedDocuments);
assert.lte(1, db.serverStatus().metrics.ttl.passes);
// Part 3
-t.createIndex({y: 1}, {expireAfterSeconds: 10000});
+t.ensureIndex({y: 1}, {expireAfterSeconds: 10000});
assert.soon(function() {
return t.count() < 12;
diff --git a/jstests/noPassthroughWithMongod/ttl_repl.js b/jstests/noPassthroughWithMongod/ttl_repl.js
index 14061ede6d1..ff15887b93b 100644
--- a/jstests/noPassthroughWithMongod/ttl_repl.js
+++ b/jstests/noPassthroughWithMongod/ttl_repl.js
@@ -50,7 +50,7 @@ printjson(secondary1col.stats());
// the correct number of docs age out
var initialExpireAfterSeconds = 20000;
assert.commandWorked(
- primarycol.createIndex({x: 1}, {expireAfterSeconds: initialExpireAfterSeconds}));
+ primarycol.ensureIndex({x: 1}, {expireAfterSeconds: initialExpireAfterSeconds}));
rt.awaitReplication();
sleep(70 * 1000); // TTL monitor runs every 60 seconds, so wait 70
diff --git a/jstests/noPassthroughWithMongod/ttl_repl_maintenance.js b/jstests/noPassthroughWithMongod/ttl_repl_maintenance.js
index 23bb9367452..0cdec8e1845 100644
--- a/jstests/noPassthroughWithMongod/ttl_repl_maintenance.js
+++ b/jstests/noPassthroughWithMongod/ttl_repl_maintenance.js
@@ -16,7 +16,7 @@ var primeSystemReplset = function() {
print("create a TTL collection");
var testDB = conn.getDB("test");
- assert.commandWorked(testDB.foo.createIndex({x: 1}, {expireAfterSeconds: 2}));
+ assert.commandWorked(testDB.foo.ensureIndex({x: 1}, {expireAfterSeconds: 2}));
};
var restartWithConfig = function() {
diff --git a/jstests/noPassthroughWithMongod/ttl_repl_secondary_disabled.js b/jstests/noPassthroughWithMongod/ttl_repl_secondary_disabled.js
index 160933c4ed8..84718bfb914 100644
--- a/jstests/noPassthroughWithMongod/ttl_repl_secondary_disabled.js
+++ b/jstests/noPassthroughWithMongod/ttl_repl_secondary_disabled.js
@@ -33,7 +33,7 @@ let primarycol = primarydb['c'];
let secondary1col = secondary1db['c'];
// create TTL index, wait for TTL monitor to kick in, then check things
-primarycol.createIndex({x: 1}, {expireAfterSeconds: 10});
+primarycol.ensureIndex({x: 1}, {expireAfterSeconds: 10});
rt.awaitReplication();
diff --git a/jstests/noPassthroughWithMongod/ttl_sharded.js b/jstests/noPassthroughWithMongod/ttl_sharded.js
index 61a97a8ce00..8ab74f35be9 100644
--- a/jstests/noPassthroughWithMongod/ttl_sharded.js
+++ b/jstests/noPassthroughWithMongod/ttl_sharded.js
@@ -32,7 +32,7 @@ assert.commandWorked(bulk.execute());
assert.eq(t.count(), 24, "initial docs not inserted");
// create the TTL index which delete anything older than ~5.5 hours
-t.createIndex({x: 1}, {expireAfterSeconds: 20000});
+t.ensureIndex({x: 1}, {expireAfterSeconds: 20000});
// split chunk in half by _id, and move one chunk to the other shard
s.adminCommand({split: ns, middle: {_id: 12}});
diff --git a/jstests/noPassthroughWithMongod/validate_command.js b/jstests/noPassthroughWithMongod/validate_command.js
index 3ef6a1d79e4..5db827f0e2a 100644
--- a/jstests/noPassthroughWithMongod/validate_command.js
+++ b/jstests/noPassthroughWithMongod/validate_command.js
@@ -27,8 +27,8 @@ for (var i = 0; i < count; i++) {
t.insert({x: i});
}
-t.createIndex({x: 1}, {name: "forward"});
-t.createIndex({x: -1}, {name: "reverse"});
+t.ensureIndex({x: 1}, {name: "forward"});
+t.ensureIndex({x: -1}, {name: "reverse"});
// TEST NORMAL VALIDATE
var output = t.validate();
diff --git a/jstests/parallel/insert.js b/jstests/parallel/insert.js
index d28eb89e220..e2dee8053d9 100644
--- a/jstests/parallel/insert.js
+++ b/jstests/parallel/insert.js
@@ -3,7 +3,7 @@ load('jstests/libs/parallelTester.js');
f = db.jstests_parallel_insert;
f.drop();
-f.createIndex({who: 1});
+f.ensureIndex({who: 1});
Random.setRandomSeed();
diff --git a/jstests/parallel/manyclients.js b/jstests/parallel/manyclients.js
index fc6dce056a8..ca31f333635 100644
--- a/jstests/parallel/manyclients.js
+++ b/jstests/parallel/manyclients.js
@@ -3,7 +3,7 @@ load('jstests/libs/parallelTester.js');
f = db.jstests_parallel_manyclients;
f.drop();
-f.createIndex({who: 1});
+f.ensureIndex({who: 1});
Random.setRandomSeed();
diff --git a/jstests/parallel/update_serializability1.js b/jstests/parallel/update_serializability1.js
index e57b51ae721..6fc41204c3c 100644
--- a/jstests/parallel/update_serializability1.js
+++ b/jstests/parallel/update_serializability1.js
@@ -10,8 +10,8 @@ for (var i = 0; i < N; i++) {
}
bulk.execute();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
s1 = startParallelShell("db.update_serializability1.update( { a : { $gte : 0 } }, { $set : { b : " +
(N + 1) + ", x : 2 } }, false, true );");
diff --git a/jstests/parallel/update_serializability2.js b/jstests/parallel/update_serializability2.js
index 16fd4ad3394..84b27049e53 100644
--- a/jstests/parallel/update_serializability2.js
+++ b/jstests/parallel/update_serializability2.js
@@ -11,8 +11,8 @@ for (var i = 0; i < N; i++) {
}
bulk.execute();
-t.createIndex({a: 1});
-t.createIndex({b: 1});
+t.ensureIndex({a: 1});
+t.ensureIndex({b: 1});
var s1 = startParallelShell(
"db.update_serializability1.update( { a : { $gte : 0 } }, { $set : { x : 2 } }, false, true );");
diff --git a/jstests/perf/compact_speed_test.js b/jstests/perf/compact_speed_test.js
index 5f1566a5967..b8fbfd2dc4a 100644
--- a/jstests/perf/compact_speed_test.js
+++ b/jstests/perf/compact_speed_test.js
@@ -29,11 +29,11 @@ if (1) {
var a = timed();
// print("index");
- t.createIndex({x: 1});
+ t.ensureIndex({x: 1});
// print("index");
- t.createIndex({y: 1});
+ t.ensureIndex({y: 1});
// print("index");
- t.createIndex({z: 1});
+ t.ensureIndex({z: 1});
a += timed();
diff --git a/jstests/perf/find1.js b/jstests/perf/find1.js
index 31710cbfd66..6a9d3b75355 100644
--- a/jstests/perf/find1.js
+++ b/jstests/perf/find1.js
@@ -13,7 +13,7 @@ function testSetup(dbConn) {
for (var i = 0; i < size; i++) {
t.save({num: i});
if (i == 0)
- t.createIndex({num: 1});
+ t.ensureIndex({num: 1});
}
}
diff --git a/jstests/perf/index1.js b/jstests/perf/index1.js
index 04b71680e66..ecb749069b9 100644
--- a/jstests/perf/index1.js
+++ b/jstests/perf/index1.js
@@ -12,11 +12,11 @@ printjson(db.serverStatus().mem);
for (var i = 0; i < 5; i++) {
nonu = Date.timeFunc(function() {
- t.createIndex({x: 1});
+ t.ensureIndex({x: 1});
});
t.dropIndex({x: 1});
u = Date.timeFunc(function() {
- t.createIndex({x: 1}, {unique: 1});
+ t.ensureIndex({x: 1}, {unique: 1});
});
t.dropIndex({x: 1});
print("non unique: " + nonu + " unique: " + u);
diff --git a/jstests/perf/remove1.js b/jstests/perf/remove1.js
index a7bf7bc1faa..09f1948572b 100644
--- a/jstests/perf/remove1.js
+++ b/jstests/perf/remove1.js
@@ -10,7 +10,7 @@ var msg = "Hello from remove test";
function testSetup(dbConn) {
var t = dbConn[collection_name];
t.drop();
- t.createIndex({num: 1});
+ t.ensureIndex({num: 1});
for (var i = 0; i < size; i++) {
t.save({num: i, msg: msg});
diff --git a/jstests/replsets/apply_ops_create_indexes.js b/jstests/replsets/apply_ops_create_indexes.js
index e3641965ce6..ebeffbb1593 100644
--- a/jstests/replsets/apply_ops_create_indexes.js
+++ b/jstests/replsets/apply_ops_create_indexes.js
@@ -7,6 +7,54 @@
load('jstests/noPassthrough/libs/index_build.js');
+let ensureIndexExists = function(testDB, collName, indexName, expectedNumIndexes) {
+ let cmd = {listIndexes: collName};
+ let res = testDB.runCommand(cmd);
+ assert.commandWorked(res, "could not run " + tojson(cmd));
+ let indexes = new DBCommandCursor(testDB, res).toArray();
+
+ assert.eq(indexes.length, expectedNumIndexes);
+
+ let foundIndex = false;
+ for (let i = 0; i < indexes.length; ++i) {
+ if (indexes[i].name == indexName) {
+ foundIndex = true;
+ }
+ }
+ assert(foundIndex,
+ "did not find the index '" + indexName +
+ "' amongst the collection indexes: " + tojson(indexes));
+};
+
+let ensureOplogEntryExists = function(localDB, indexName) {
+ // Make sure the oplog entry for index creation exists in the oplog.
+ let cmd = {find: "oplog.rs"};
+ let res = localDB.runCommand(cmd);
+ assert.commandWorked(res, "could not run " + tojson(cmd));
+ let cursor = new DBCommandCursor(localDB, res);
+ let errMsg = "expected more data from command " + tojson(cmd) + ", with result " + tojson(res);
+ assert(cursor.hasNext(), errMsg);
+ let oplog = localDB.getCollection("oplog.rs");
+
+ // If two phase index builds are enabled, index creation will show up in the oplog as a pair of
+ // startIndexBuild and commitIndexBuild oplog entries rather than a single createIndexes entry.
+ let query = {
+ $and: [
+ {"o.startIndexBuild": {$exists: true}},
+ {"o.indexes.0.name": indexName},
+ ],
+ };
+ let resCursor = oplog.find(query);
+ assert.eq(resCursor.count(),
+ 1,
+ "Expected the query " + tojson(query) + " to return exactly 1 document");
+ query = {$and: [{"o.commitIndexBuild": {$exists: true}}, {"o.indexes.0.name": indexName}]};
+ resCursor = oplog.find(query);
+ assert.eq(resCursor.count(),
+ 1,
+ "Expected the query " + tojson(query) + " to return exactly 1 document");
+};
+
let rst = new ReplSetTest({nodes: 3});
rst.startSet();
rst.initiate();
diff --git a/jstests/replsets/background_index.js b/jstests/replsets/background_index.js
index a09138a9e19..662abef771d 100644
--- a/jstests/replsets/background_index.js
+++ b/jstests/replsets/background_index.js
@@ -23,7 +23,7 @@ for (var i = 0; i < 100; i++) {
}
// Add a background index.
-coll.createIndex({x: 1}, {background: true});
+coll.ensureIndex({x: 1}, {background: true});
// Rename the collection.
assert.commandWorked(
diff --git a/jstests/replsets/buildindexes.js b/jstests/replsets/buildindexes.js
index 95356d24e1b..3be0ba68896 100644
--- a/jstests/replsets/buildindexes.js
+++ b/jstests/replsets/buildindexes.js
@@ -26,7 +26,7 @@ for (var i in secondaryConns) {
}
replTest.awaitReplication();
-primary.x.createIndex({y: 1});
+primary.x.ensureIndex({y: 1});
for (i = 0; i < 100; i++) {
primary.x.insert({x: 1, y: "abc", c: 1});
diff --git a/jstests/replsets/bulk_api_wc.js b/jstests/replsets/bulk_api_wc.js
index 1c90537d2be..591ad1aef58 100644
--- a/jstests/replsets/bulk_api_wc.js
+++ b/jstests/replsets/bulk_api_wc.js
@@ -28,7 +28,7 @@ var executeTests = function() {
// Create a unique index, legacy writes validate too early to use invalid documents for
// write
// error testing
- coll.createIndex({a: 1}, {unique: true});
+ coll.ensureIndex({a: 1}, {unique: true});
//
// Ordered
diff --git a/jstests/replsets/drop_collections_two_phase_rename_drop_target.js b/jstests/replsets/drop_collections_two_phase_rename_drop_target.js
index 9aa9a15c9c1..5191fb47127 100644
--- a/jstests/replsets/drop_collections_two_phase_rename_drop_target.js
+++ b/jstests/replsets/drop_collections_two_phase_rename_drop_target.js
@@ -52,8 +52,8 @@ let shortIndexName = "short_name";
// In the target collection, which will be dropped, create one index with a "too long" name, and
// one with a name of acceptable size.
-assert.commandWorked(toColl.createIndex({a: 1}, {name: longIndexName}));
-assert.commandWorked(toColl.createIndex({b: 1}, {name: shortIndexName}));
+assert.commandWorked(toColl.ensureIndex({a: 1}, {name: longIndexName}));
+assert.commandWorked(toColl.ensureIndex({b: 1}, {name: shortIndexName}));
// Insert documents into both collections so that we can tell them apart.
assert.commandWorked(fromColl.insert({_id: 'from'}));
diff --git a/jstests/replsets/initial_sync4.js b/jstests/replsets/initial_sync4.js
index 1860db6d1c8..35dbd632715 100644
--- a/jstests/replsets/initial_sync4.js
+++ b/jstests/replsets/initial_sync4.js
@@ -17,7 +17,7 @@
jsTestLog("2. Insert some data");
var N = 5000;
- mc.createIndex({x: 1});
+ mc.ensureIndex({x: 1});
var bulk = mc.initializeUnorderedBulkOp();
for (var i = 0; i < N; ++i) {
bulk.insert({_id: i, x: i, a: {}});
diff --git a/jstests/replsets/initial_sync_ambiguous_index.js b/jstests/replsets/initial_sync_ambiguous_index.js
index 2398243f301..c50324db935 100644
--- a/jstests/replsets/initial_sync_ambiguous_index.js
+++ b/jstests/replsets/initial_sync_ambiguous_index.js
@@ -32,7 +32,7 @@ rst.initiate();
const primaryColl = rst.getPrimary().getDB(dbName).getCollection(collectionName);
// Create the index.
-primaryColl.createIndex({"a.0": 1});
+primaryColl.ensureIndex({"a.0": 1});
// Insert the initial document set.
for (let i = 0; i < initialDocs; ++i) {
diff --git a/jstests/replsets/initial_sync_move_forward.js b/jstests/replsets/initial_sync_move_forward.js
index 8a2c6589d41..311ab315536 100644
--- a/jstests/replsets/initial_sync_move_forward.js
+++ b/jstests/replsets/initial_sync_move_forward.js
@@ -36,7 +36,7 @@ bulk.insert({_id: count - 1, x: count - 1, longString: longString});
assert.commandWorked(bulk.execute());
// Create a unique index on {x: 1}.
-assert.commandWorked(primaryColl.createIndex({x: 1}, {unique: true}));
+assert.commandWorked(primaryColl.ensureIndex({x: 1}, {unique: true}));
// Add a secondary.
var secondary =
diff --git a/jstests/replsets/reindex.js b/jstests/replsets/reindex.js
index 211fbe55001..454e72f25e8 100644
--- a/jstests/replsets/reindex.js
+++ b/jstests/replsets/reindex.js
@@ -26,7 +26,7 @@ const secondaryDB = secondary.getDB(dbName);
const secondaryColl = secondaryDB.getCollection(collName);
assert.commandWorked(primaryColl.insert({a: 1000}));
-assert.commandWorked(primaryColl.createIndex({a: 1}));
+assert.commandWorked(primaryColl.ensureIndex({a: 1}));
replTest.awaitReplication();
replTest.awaitReplication();
@@ -59,7 +59,7 @@ const testDB = standalone.getDB(dbName);
const testColl = testDB.getCollection(collName);
assert.commandWorked(testColl.insert({a: 1000}));
-assert.commandWorked(testColl.createIndex({a: 1}));
+assert.commandWorked(testColl.ensureIndex({a: 1}));
assert.eq(2, testColl.getIndexes().length, "Standalone didn't have proper indexes before reindex");
assert.commandWorked(testColl.reIndex());
diff --git a/jstests/replsets/replset1.js b/jstests/replsets/replset1.js
index 7ce4610495e..3ad42615db9 100644
--- a/jstests/replsets/replset1.js
+++ b/jstests/replsets/replset1.js
@@ -123,7 +123,7 @@ var doTest = function(signal) {
});
t.save({a: 1000});
- t.createIndex({a: 1});
+ t.ensureIndex({a: 1});
replTest.awaitReplication();
ts.forEach(function(z) {
diff --git a/jstests/replsets/temp_namespace.js b/jstests/replsets/temp_namespace.js
index a6a7a839ea6..f8a6f854a68 100644
--- a/jstests/replsets/temp_namespace.js
+++ b/jstests/replsets/temp_namespace.js
@@ -26,10 +26,10 @@ var secondaryDB = secondary.getDB('test');
// set up collections
assert.commandWorked(primaryDB.runCommand(
{applyOps: [{op: "c", ns: primaryDB.getName() + ".$cmd", o: {create: "temp1", temp: true}}]}));
-primaryDB.temp1.createIndex({x: 1});
+primaryDB.temp1.ensureIndex({x: 1});
assert.commandWorked(primaryDB.runCommand(
{applyOps: [{op: "c", ns: primaryDB.getName() + ".$cmd", o: {create: "temp2", temp: 1}}]}));
-primaryDB.temp2.createIndex({x: 1});
+primaryDB.temp2.ensureIndex({x: 1});
assert.commandWorked(primaryDB.runCommand(
{applyOps: [{op: "c", ns: primaryDB.getName() + ".$cmd", o: {create: "keep1", temp: false}}]}));
assert.commandWorked(primaryDB.runCommand(
diff --git a/jstests/sharding/addshard1.js b/jstests/sharding/addshard1.js
index e7aa1920d6b..e43a2a48553 100644
--- a/jstests/sharding/addshard1.js
+++ b/jstests/sharding/addshard1.js
@@ -62,7 +62,7 @@ assert.eq(
numObjs, sdb1.foo.count(), "wrong count after moving datbase that existed before addshard");
// make sure we can shard the original collections
-sdb1.foo.createIndex({a: 1}, {unique: true}); // can't shard populated collection without an index
+sdb1.foo.ensureIndex({a: 1}, {unique: true}); // can't shard populated collection without an index
s.adminCommand({enablesharding: "testDB"});
s.adminCommand({shardcollection: "testDB.foo", key: {a: 1}});
s.adminCommand({split: "testDB.foo", middle: {a: Math.floor(numObjs / 2)}});
diff --git a/jstests/sharding/array_shard_key.js b/jstests/sharding/array_shard_key.js
index 686d1d1085f..3acf841a1b0 100644
--- a/jstests/sharding/array_shard_key.js
+++ b/jstests/sharding/array_shard_key.js
@@ -71,7 +71,7 @@ value = coll.findOne({i: 1});
assert.commandWorked(coll.remove(Object.extend(value, {i: 1})));
assert.eq(coll.find().itcount(), 0);
-coll.createIndex({_id: 1, i: 1, j: 1});
+coll.ensureIndex({_id: 1, i: 1, j: 1});
// Can insert document that will make index into a multi-key as long as it's not part of shard
// key.
coll.remove({});
@@ -119,7 +119,7 @@ for (var i = 0; i < 10; i++) {
assert.commandWorked(coll.insert({i: [i, i + 1]}));
}
-coll.createIndex({_id: 1, i: 1});
+coll.ensureIndex({_id: 1, i: 1});
try {
st.shardColl(coll, {_id: 1, i: 1}, {_id: ObjectId(), i: 1});
@@ -136,7 +136,7 @@ for (var i = 0; i < 10; i++) {
assert.commandWorked(coll.insert({i: i}));
}
-coll.createIndex({_id: 1, i: 1});
+coll.ensureIndex({_id: 1, i: 1});
st.shardColl(coll, {_id: 1, i: 1}, {_id: ObjectId(), i: 1});
diff --git a/jstests/sharding/bulk_insert.js b/jstests/sharding/bulk_insert.js
index a36c7c6c091..93192010dd9 100644
--- a/jstests/sharding/bulk_insert.js
+++ b/jstests/sharding/bulk_insert.js
@@ -22,8 +22,8 @@ st.ensurePrimaryShard(collSh.getDB() + "", st.shard0.shardName);
assert.commandWorked(admin.runCommand({movePrimary: collUn.getDB() + "", to: st.shard1.shardName}));
-printjson(collSh.createIndex({ukey: 1}, {unique: true}));
-printjson(collUn.createIndex({ukey: 1}, {unique: true}));
+printjson(collSh.ensureIndex({ukey: 1}, {unique: true}));
+printjson(collUn.ensureIndex({ukey: 1}, {unique: true}));
assert.commandWorked(admin.runCommand({shardCollection: collSh + "", key: {ukey: 1}}));
assert.commandWorked(admin.runCommand({split: collSh + "", middle: {ukey: 0}}));
diff --git a/jstests/sharding/coll_epoch_test1.js b/jstests/sharding/coll_epoch_test1.js
index 115418017a2..4249265797e 100644
--- a/jstests/sharding/coll_epoch_test1.js
+++ b/jstests/sharding/coll_epoch_test1.js
@@ -45,7 +45,7 @@ st.configRS.awaitLastOpCommitted();
jsTest.log("Re-enabling sharding with a different key...");
st.ensurePrimaryShard(coll.getDB().getName(), st.shard1.shardName);
-assert.commandWorked(coll.createIndex({notId: 1}));
+assert.commandWorked(coll.ensureIndex({notId: 1}));
assert.commandWorked(admin.runCommand({shardCollection: coll + "", key: {notId: 1}}));
bulk = insertMongos.getCollection(coll + "").initializeUnorderedBulkOp();
diff --git a/jstests/sharding/covered_shard_key_indexes.js b/jstests/sharding/covered_shard_key_indexes.js
index 300632c0d76..773a3d0927b 100644
--- a/jstests/sharding/covered_shard_key_indexes.js
+++ b/jstests/sharding/covered_shard_key_indexes.js
@@ -25,19 +25,19 @@ assert.commandWorked(
assert.commandWorked(coll.insert({_id: true, a: true, b: true}));
// Index without shard key query - not covered
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
assert.eq(1, coll.find({a: true}).explain(true).executionStats.totalDocsExamined);
assert.eq(1, coll.find({a: true}, {_id: 1, a: 1}).explain(true).executionStats.totalDocsExamined);
// Index with shard key query - covered when projecting
assert.commandWorked(coll.dropIndexes());
-assert.commandWorked(coll.createIndex({a: 1, _id: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1, _id: 1}));
assert.eq(1, coll.find({a: true}).explain(true).executionStats.totalDocsExamined);
assert.eq(0, coll.find({a: true}, {_id: 1, a: 1}).explain(true).executionStats.totalDocsExamined);
// Compound index with shard key query - covered when projecting
assert.commandWorked(coll.dropIndexes());
-assert.commandWorked(coll.createIndex({a: 1, b: 1, _id: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: 1, _id: 1}));
assert.eq(1, coll.find({a: true, b: true}).explain(true).executionStats.totalDocsExamined);
assert.eq(
0,
@@ -52,7 +52,7 @@ st.printShardingStatus();
assert.commandWorked(coll.insert({_id: true, a: true, b: true}));
// Index without shard key query - not covered
-assert.commandWorked(coll.createIndex({a: 1}));
+assert.commandWorked(coll.ensureIndex({a: 1}));
assert.eq(1, coll.find({a: true}).explain(true).executionStats.totalDocsExamined);
assert.eq(1, coll.find({a: true}, {_id: 0, a: 1}).explain(true).executionStats.totalDocsExamined);
@@ -70,7 +70,7 @@ st.printShardingStatus();
assert.commandWorked(coll.insert({_id: true, a: true, b: true, c: true, d: true}));
// Index without shard key query - not covered
-assert.commandWorked(coll.createIndex({c: 1}));
+assert.commandWorked(coll.ensureIndex({c: 1}));
assert.eq(1, coll.find({c: true}).explain(true).executionStats.totalDocsExamined);
assert.eq(1,
coll.find({c: true}, {_id: 0, a: 1, b: 1, c: 1})
@@ -79,7 +79,7 @@ assert.eq(1,
// Index with shard key query - covered when projecting
assert.commandWorked(coll.dropIndex({c: 1}));
-assert.commandWorked(coll.createIndex({c: 1, b: 1, a: 1}));
+assert.commandWorked(coll.ensureIndex({c: 1, b: 1, a: 1}));
assert.eq(1, coll.find({c: true}).explain(true).executionStats.totalDocsExamined);
assert.eq(0,
coll.find({c: true}, {_id: 0, a: 1, b: 1, c: 1})
@@ -88,7 +88,7 @@ assert.eq(0,
// Compound index with shard key query - covered when projecting
assert.commandWorked(coll.dropIndex({c: 1, b: 1, a: 1}));
-assert.commandWorked(coll.createIndex({c: 1, d: 1, a: 1, b: 1, _id: 1}));
+assert.commandWorked(coll.ensureIndex({c: 1, d: 1, a: 1, b: 1, _id: 1}));
assert.eq(1, coll.find({c: true, d: true}).explain(true).executionStats.totalDocsExamined);
assert.eq(0,
coll.find({c: true, d: true}, {a: 1, b: 1, c: 1, d: 1})
@@ -104,7 +104,7 @@ st.printShardingStatus();
assert.commandWorked(coll.insert({_id: true, a: {b: true}, c: true}));
// Index without shard key query - not covered
-assert.commandWorked(coll.createIndex({c: 1}));
+assert.commandWorked(coll.ensureIndex({c: 1}));
assert.eq(1, coll.find({c: true}).explain(true).executionStats.totalDocsExamined);
assert.eq(
1,
@@ -112,7 +112,7 @@ assert.eq(
// Index with shard key query - can be covered given the appropriate projection.
assert.commandWorked(coll.dropIndex({c: 1}));
-assert.commandWorked(coll.createIndex({c: 1, 'a.b': 1}));
+assert.commandWorked(coll.ensureIndex({c: 1, 'a.b': 1}));
assert.eq(1, coll.find({c: true}).explain(true).executionStats.totalDocsExamined);
assert.eq(
0,
@@ -127,7 +127,7 @@ st.printShardingStatus();
assert.commandWorked(st.shard0.getCollection(coll.toString()).insert({_id: "bad data", c: true}));
// Index without shard key query - not covered but succeeds
-assert.commandWorked(coll.createIndex({c: 1}));
+assert.commandWorked(coll.ensureIndex({c: 1}));
var explain = coll.find({c: true}).explain(true).executionStats;
assert.eq(1, explain.nReturned);
assert.eq(1, explain.totalDocsExamined);
@@ -137,7 +137,7 @@ assert.eq(0, getChunkSkips(explain.executionStages.shards[0].executionStages));
//
// NOTE: This is weird and only a result of the fact that we don't have a dedicated "does not
// exist" value for indexes
-assert.commandWorked(coll.createIndex({c: 1, a: 1}));
+assert.commandWorked(coll.ensureIndex({c: 1, a: 1}));
var explain = coll.find({c: true}, {_id: 0, a: 1, c: 1}).explain(true).executionStats;
assert.eq(1, explain.nReturned);
assert.eq(0, explain.totalDocsExamined);
diff --git a/jstests/sharding/create_idx_empty_primary.js b/jstests/sharding/create_idx_empty_primary.js
index 462a866e236..2641d7f7416 100644
--- a/jstests/sharding/create_idx_empty_primary.js
+++ b/jstests/sharding/create_idx_empty_primary.js
@@ -17,7 +17,7 @@ assert.commandWorked(
assert.commandWorked(testDB.user.insert({_id: 0}));
-var res = testDB.user.createIndex({i: 1});
+var res = testDB.user.ensureIndex({i: 1});
assert.commandWorked(res);
var indexes = testDB.user.getIndexes();
diff --git a/jstests/sharding/delete_during_migrate.js b/jstests/sharding/delete_during_migrate.js
index 3477f57bc85..108097bf808 100644
--- a/jstests/sharding/delete_during_migrate.js
+++ b/jstests/sharding/delete_during_migrate.js
@@ -28,7 +28,7 @@ for (var i = 0; i < 200000; i++) {
assert.commandWorked(bulk.execute());
// enable sharding of the collection. Only 1 chunk.
-t.createIndex({a: 1});
+t.ensureIndex({a: 1});
assert.commandWorked(st.s0.adminCommand({shardcollection: ns, key: {a: 1}}));
diff --git a/jstests/sharding/drop_indexes_with_stale_config_error.js b/jstests/sharding/drop_indexes_with_stale_config_error.js
index 20d969fd865..f84bcc88941 100644
--- a/jstests/sharding/drop_indexes_with_stale_config_error.js
+++ b/jstests/sharding/drop_indexes_with_stale_config_error.js
@@ -25,7 +25,7 @@ assert.commandWorked(st.s.adminCommand({split: ns, middle: {x: 0}}));
assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {x: 100}, to: st.shard1.shardName}));
flushRoutersAndRefreshShardMetadata(st, {ns});
-assert.commandWorked(mongos0Coll.createIndex({x: 1}));
+assert.commandWorked(mongos0Coll.ensureIndex({x: 1}));
// Move chunk without refreshing the recipient so that the recipient shard throws a
// StaleShardVersion error upon receiving the drop index command.
diff --git a/jstests/sharding/features2.js b/jstests/sharding/features2.js
index 1cae75c30ae..9626392a43f 100644
--- a/jstests/sharding/features2.js
+++ b/jstests/sharding/features2.js
@@ -12,7 +12,7 @@ let db = s.getDB("test");
db.foo.save({x: 1});
db.foo.save({x: 2});
db.foo.save({x: 3});
-db.foo.createIndex({x: 1});
+db.foo.ensureIndex({x: 1});
let a = s.shard0.getDB("test");
let b = s.shard1.getDB("test");
@@ -73,7 +73,7 @@ db.mr.save({x: 1, tags: ["a", "b"]});
db.mr.save({x: 2, tags: ["b", "c"]});
db.mr.save({x: 3, tags: ["c", "a"]});
db.mr.save({x: 4, tags: ["b", "c"]});
-db.mr.createIndex({x: 1});
+db.mr.ensureIndex({x: 1});
let m = function() {
this.tags.forEach(function(z) {
diff --git a/jstests/sharding/fts_score_sort_sharded.js b/jstests/sharding/fts_score_sort_sharded.js
index 1532ccf724b..262a676d89c 100644
--- a/jstests/sharding/fts_score_sort_sharded.js
+++ b/jstests/sharding/fts_score_sort_sharded.js
@@ -26,7 +26,7 @@ assert.commandWorked(coll.insert({_id: 1, a: "pizza"}));
assert.commandWorked(coll.insert({_id: -1, a: "pizza pizza"}));
assert.commandWorked(coll.insert({_id: 2, a: "pizza pizza pizza"}));
assert.commandWorked(coll.insert({_id: -2, a: "pizza pizza pizza pizza"}));
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
//
// Execute query with sort on document score, verify results are in correct order.
@@ -76,7 +76,7 @@ assert.commandWorked(coll.insert({_id: 0, a: "pizza", b: [1, 4]}));
assert.commandWorked(coll.insert({_id: 1, a: "pizza pizza", b: [6, 7]}));
assert.commandWorked(coll.insert({_id: 2, a: "pizza", b: [2, 3]}));
assert.commandWorked(coll.insert({_id: 3, a: "pizza pizza", b: [5, 8]}));
-assert.commandWorked(coll.createIndex({a: "text"}));
+assert.commandWorked(coll.ensureIndex({a: "text"}));
results = coll.find({$text: {$search: "pizza"}}, {s: {$meta: "textScore"}})
.sort({s: {$meta: "textScore"}, b: 1})
diff --git a/jstests/sharding/hash_shard_non_empty.js b/jstests/sharding/hash_shard_non_empty.js
index 01692518b66..865c103ce14 100644
--- a/jstests/sharding/hash_shard_non_empty.js
+++ b/jstests/sharding/hash_shard_non_empty.js
@@ -12,7 +12,7 @@ s.stopBalancer();
db.getCollection(coll).insert({a: 1});
-db.getCollection(coll).createIndex({a: "hashed"});
+db.getCollection(coll).ensureIndex({a: "hashed"});
var res = db.adminCommand({shardcollection: dbname + "." + coll, key: {a: "hashed"}});
assert.eq(res.ok, 1, "shardcollection didn't work");
s.printShardingStatus();
diff --git a/jstests/sharding/hash_shard_unique_compound.js b/jstests/sharding/hash_shard_unique_compound.js
index acec60bf667..460d28789b9 100644
--- a/jstests/sharding/hash_shard_unique_compound.js
+++ b/jstests/sharding/hash_shard_unique_compound.js
@@ -21,7 +21,7 @@ assert.commandWorked(db.adminCommand({enablesharding: dbName}));
assert.commandWorked(db.adminCommand({shardcollection: ns, key: {a: "hashed"}}));
// Create unique index
-assert.commandWorked(coll.createIndex({a: 1, b: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: 1}, {unique: true}));
jsTest.log("------ indexes -------");
jsTest.log(tojson(coll.getIndexes()));
@@ -31,7 +31,7 @@ jsTest.log("------ dropping sharded collection to start part 2 -------");
coll.drop();
// Create unique index
-assert.commandWorked(coll.createIndex({a: 1, b: 1}, {unique: true}));
+assert.commandWorked(coll.ensureIndex({a: 1, b: 1}, {unique: true}));
// shard a fresh collection using a hashed shard key
assert.commandWorked(db.adminCommand({shardcollection: ns, key: {a: "hashed"}}),
diff --git a/jstests/sharding/index1.js b/jstests/sharding/index1.js
index 019a1100919..67c4c3ceeb6 100644
--- a/jstests/sharding/index1.js
+++ b/jstests/sharding/index1.js
@@ -23,8 +23,8 @@ for (var i = 0; i < 22; i++) {
if (i == 0) {
// Unique index exists, but not the right one.
- coll.createIndex({num: 1}, {unique: true});
- coll.createIndex({x: 1});
+ coll.ensureIndex({num: 1}, {unique: true});
+ coll.ensureIndex({x: 1});
passed = false;
try {
@@ -37,8 +37,8 @@ for (var i = 0; i < 22; i++) {
}
if (i == 1) {
// Unique index exists as prefix, also index exists
- coll.createIndex({x: 1});
- coll.createIndex({x: 1, num: 1}, {unique: true});
+ coll.ensureIndex({x: 1});
+ coll.ensureIndex({x: 1, num: 1}, {unique: true});
try {
s.adminCommand({shardcollection: "" + coll, key: {x: 1}});
@@ -49,8 +49,8 @@ for (var i = 0; i < 22; i++) {
}
if (i == 2) {
// Non-unique index exists as prefix, also index exists. No unique index.
- coll.createIndex({x: 1});
- coll.createIndex({x: 1, num: 1});
+ coll.ensureIndex({x: 1});
+ coll.ensureIndex({x: 1, num: 1});
passed = false;
try {
@@ -66,8 +66,8 @@ for (var i = 0; i < 22; i++) {
}
if (i == 3) {
// Unique index exists as prefix, also unique index exists
- coll.createIndex({num: 1}, {unique: true});
- coll.createIndex({num: 1, x: 1}, {unique: true});
+ coll.ensureIndex({num: 1}, {unique: true});
+ coll.ensureIndex({num: 1, x: 1}, {unique: true});
try {
s.adminCommand({shardcollection: "" + coll, key: {num: 1}, unique: true});
@@ -78,7 +78,7 @@ for (var i = 0; i < 22; i++) {
}
if (i == 4) {
// Unique index exists as id, also unique prefix index exists
- coll.createIndex({_id: 1, num: 1}, {unique: true});
+ coll.ensureIndex({_id: 1, num: 1}, {unique: true});
try {
s.adminCommand({shardcollection: "" + coll, key: {_id: 1}, unique: true});
@@ -89,7 +89,7 @@ for (var i = 0; i < 22; i++) {
}
if (i == 5) {
// Unique index exists as id, also unique prefix index exists
- coll.createIndex({_id: 1, num: 1}, {unique: true});
+ coll.ensureIndex({_id: 1, num: 1}, {unique: true});
try {
s.adminCommand({shardcollection: "" + coll, key: {_id: 1, num: 1}, unique: true});
@@ -102,7 +102,7 @@ for (var i = 0; i < 22; i++) {
coll.remove({});
// Unique index does not exist, also unique prefix index exists
- coll.createIndex({num: 1, _id: 1}, {unique: true});
+ coll.ensureIndex({num: 1, _id: 1}, {unique: true});
try {
s.adminCommand({shardcollection: "" + coll, key: {num: 1}, unique: true});
@@ -165,8 +165,8 @@ for (var i = 0; i < 22; i++) {
}
if (i == 9) {
// Unique index exists on a different field as well
- coll.createIndex({num: 1}, {unique: true});
- coll.createIndex({x: 1});
+ coll.ensureIndex({num: 1}, {unique: true});
+ coll.ensureIndex({x: 1});
passed = false;
try {
@@ -189,7 +189,7 @@ for (var i = 0; i < 22; i++) {
assert(!passed, "Should not be able to shard without index");
// now add containing index and try sharding by prefix
- coll.createIndex({num: 1, x: 1});
+ coll.ensureIndex({num: 1, x: 1});
try {
s.adminCommand({shardcollection: "" + coll, key: {num: 1}});
@@ -208,7 +208,7 @@ for (var i = 0; i < 22; i++) {
coll.remove({});
// empty collection with useful index. check new index not created
- coll.createIndex({num: 1, x: 1});
+ coll.ensureIndex({num: 1, x: 1});
try {
s.adminCommand({shardcollection: "" + coll, key: {num: 1}});
@@ -226,7 +226,7 @@ for (var i = 0; i < 22; i++) {
if (i == 12) {
// check multikey values for x make index unusable for shard key
coll.save({num: 100, x: [2, 3]});
- coll.createIndex({num: 1, x: 1});
+ coll.ensureIndex({num: 1, x: 1});
passed = false;
try {
@@ -239,7 +239,7 @@ for (var i = 0; i < 22; i++) {
}
if (i == 13) {
coll.save({num: [100, 200], x: 10});
- coll.createIndex({num: 1, x: 1});
+ coll.ensureIndex({num: 1, x: 1});
passed = false;
try {
@@ -252,7 +252,7 @@ for (var i = 0; i < 22; i++) {
}
if (i == 14) {
coll.save({num: 100, x: 10, y: [1, 2]});
- coll.createIndex({num: 1, x: 1, y: 1});
+ coll.ensureIndex({num: 1, x: 1, y: 1});
passed = false;
try {
@@ -265,7 +265,7 @@ for (var i = 0; i < 22; i++) {
}
if (i == 15) {
// try sharding with a hashed index
- coll.createIndex({num: "hashed"});
+ coll.ensureIndex({num: "hashed"});
try {
s.adminCommand({shardcollection: "" + coll, key: {num: "hashed"}});
@@ -276,7 +276,7 @@ for (var i = 0; i < 22; i++) {
}
if (i == 16) {
// create hashed index, but try to declare it unique when sharding
- coll.createIndex({num: "hashed"});
+ coll.ensureIndex({num: "hashed"});
passed = false;
try {
@@ -289,8 +289,8 @@ for (var i = 0; i < 22; i++) {
}
if (i == 17) {
// create hashed index, but unrelated unique index present
- coll.createIndex({x: "hashed"});
- coll.createIndex({num: 1}, {unique: true});
+ coll.ensureIndex({x: "hashed"});
+ coll.ensureIndex({num: 1}, {unique: true});
passed = false;
try {
@@ -303,8 +303,8 @@ for (var i = 0; i < 22; i++) {
}
if (i == 18) {
// create hashed index, and a regular unique index exists on same field
- coll.createIndex({num: "hashed"});
- coll.createIndex({num: 1}, {unique: true});
+ coll.ensureIndex({num: "hashed"});
+ coll.ensureIndex({num: 1}, {unique: true});
try {
s.adminCommand({shardcollection: "" + coll, key: {num: "hashed"}});
@@ -315,7 +315,7 @@ for (var i = 0; i < 22; i++) {
}
if (i == 19) {
// Create sparse index.
- coll.createIndex({x: 1}, {sparse: true});
+ coll.ensureIndex({x: 1}, {sparse: true});
passed = false;
try {
@@ -328,7 +328,7 @@ for (var i = 0; i < 22; i++) {
}
if (i == 20) {
// Create partial index.
- coll.createIndex({x: 1}, {filter: {num: {$gt: 1}}});
+ coll.ensureIndex({x: 1}, {filter: {num: {$gt: 1}}});
passed = false;
try {
@@ -344,8 +344,8 @@ for (var i = 0; i < 22; i++) {
// where
// both are prefixed by the shard key.
- coll.createIndex({x: 1, num: 1}, {filter: {num: {$gt: 1}}});
- coll.createIndex({x: 1, num: -1});
+ coll.ensureIndex({x: 1, num: 1}, {filter: {num: {$gt: 1}}});
+ coll.ensureIndex({x: 1, num: -1});
try {
s.adminCommand({shardcollection: "" + coll, key: {x: 1}});
diff --git a/jstests/sharding/key_many.js b/jstests/sharding/key_many.js
index e3ef862e8e8..86ac72100bd 100644
--- a/jstests/sharding/key_many.js
+++ b/jstests/sharding/key_many.js
@@ -219,7 +219,7 @@ for (var i = 0; i < types.length; i++) {
assert.commandWorked(
c.update(makeObjectDotted(curT.values[3]), {$set: {xx: 17}}, {upsert: true}));
- assert.commandWorked(c.createIndex({_id: 1}));
+ assert.commandWorked(c.ensureIndex({_id: 1}));
// multi update
var mysum = 0;
diff --git a/jstests/sharding/limit_push.js b/jstests/sharding/limit_push.js
index a6773f1263e..ef6b7a1c903 100644
--- a/jstests/sharding/limit_push.js
+++ b/jstests/sharding/limit_push.js
@@ -9,7 +9,7 @@ var db = s.getDB("test");
for (i = 0; i < 100; i++) {
db.limit_push.insert({_id: i, x: i});
}
-db.limit_push.createIndex({x: 1});
+db.limit_push.ensureIndex({x: 1});
assert.eq(100, db.limit_push.find().length(), "Incorrect number of documents");
// Shard the collection
diff --git a/jstests/sharding/mongos_validate_writes.js b/jstests/sharding/mongos_validate_writes.js
index 0852dccf763..fbcd98249f6 100644
--- a/jstests/sharding/mongos_validate_writes.js
+++ b/jstests/sharding/mongos_validate_writes.js
@@ -19,7 +19,7 @@ var staleCollB = staleMongosB.getCollection(coll + "");
assert.commandWorked(admin.runCommand({enableSharding: coll.getDB() + ""}));
st.ensurePrimaryShard(coll.getDB().getName(), st.shard1.shardName);
-coll.createIndex({a: 1});
+coll.ensureIndex({a: 1});
// Shard the collection on {a: 1} and move one chunk to another shard. Updates need to be across
// two shards to trigger an error, otherwise they are versioned and will succeed after raising
@@ -32,7 +32,7 @@ staleCollB.findOne();
// Change the collection sharding state
coll.drop();
-coll.createIndex({b: 1});
+coll.ensureIndex({b: 1});
st.shardColl(coll, {b: 1}, {b: 0}, {b: 1}, coll.getDB(), true);
// Make sure that we can successfully insert, even though we have stale state
@@ -40,7 +40,7 @@ assert.commandWorked(staleCollA.insert({b: "b"}));
// Change the collection sharding state
coll.drop();
-coll.createIndex({c: 1});
+coll.ensureIndex({c: 1});
st.shardColl(coll, {c: 1}, {c: 0}, {c: 1}, coll.getDB(), true);
// Make sure we can successfully upsert, even though we have stale state
@@ -52,7 +52,7 @@ assert.commandFailedWithCode(staleCollB.update({b: "b"}, {b: "b"}, true),
// Change the collection sharding state
coll.drop();
-coll.createIndex({d: 1});
+coll.ensureIndex({d: 1});
st.shardColl(coll, {d: 1}, {d: 0}, {d: 1}, coll.getDB(), true);
// Make sure we can successfully update, even though we have stale state
@@ -68,7 +68,7 @@ assert.eq(staleCollB.findOne().x, "x");
// Change the collection sharding state
coll.drop();
-coll.createIndex({e: 1});
+coll.ensureIndex({e: 1});
// Deletes need to be across two shards to trigger an error.
st.ensurePrimaryShard(coll.getDB().getName(), st.shard0.shardName);
st.shardColl(coll, {e: 1}, {e: 0}, {e: 1}, coll.getDB(), true);
diff --git a/jstests/sharding/move_chunk_missing_idx.js b/jstests/sharding/move_chunk_missing_idx.js
index f81369a4a48..16cc64ddddd 100644
--- a/jstests/sharding/move_chunk_missing_idx.js
+++ b/jstests/sharding/move_chunk_missing_idx.js
@@ -19,7 +19,7 @@ testDB.adminCommand({shardCollection: 'test.user', key: {x: 1}});
// 2. Split chunk into 3 parts.
// 3. Move 1 chunk to 2nd shard - should have no issues
-testDB.user.createIndex({a: 1, b: 1});
+testDB.user.ensureIndex({a: 1, b: 1});
testDB.adminCommand({split: 'test.user', middle: {x: 0}});
testDB.adminCommand({split: 'test.user', middle: {x: 10}});
diff --git a/jstests/sharding/move_chunk_wc.js b/jstests/sharding/move_chunk_wc.js
index b37e2392203..7dc75204d19 100644
--- a/jstests/sharding/move_chunk_wc.js
+++ b/jstests/sharding/move_chunk_wc.js
@@ -30,7 +30,7 @@ var numberDoc = 20;
var s0 = st.shard0.shardName;
var s1 = st.shard1.shardName;
-coll.createIndex({x: 1}, {unique: true});
+coll.ensureIndex({x: 1}, {unique: true});
st.ensurePrimaryShard(db.toString(), s0);
st.shardColl(collName, {x: 1}, {x: numberDoc / 2}, {x: numberDoc / 2}, db.toString(), true);
diff --git a/jstests/sharding/prefix_shard_key.js b/jstests/sharding/prefix_shard_key.js
index b25df2d838b..fdec2e887ec 100644
--- a/jstests/sharding/prefix_shard_key.js
+++ b/jstests/sharding/prefix_shard_key.js
@@ -49,7 +49,7 @@ assert.throws(function() {
});
// create usable index
-assert.commandWorked(coll.createIndex({num: 1, x: 1}));
+assert.commandWorked(coll.ensureIndex({num: 1, x: 1}));
// usable index, doc with empty 'num' value
assert.commandWorked(coll.insert({x: -5}));
@@ -84,7 +84,7 @@ assert.commandWorked(s.s0.adminCommand({
// Migrations and splits will still work on a sharded collection that only has multi key
// index.
-db.user.createIndex({num: 1, x: 1});
+db.user.ensureIndex({num: 1, x: 1});
db.adminCommand({shardCollection: 'test.user', key: {num: 1}});
var indexCount = db.user.getIndexes().length;
@@ -152,11 +152,11 @@ for (i = 0; i < 3; i++) {
// declare a longer index
if (i == 0) {
- assert.commandWorked(coll2.createIndex({skey: 1, extra: 1}));
+ assert.commandWorked(coll2.ensureIndex({skey: 1, extra: 1}));
} else if (i == 1) {
- assert.commandWorked(coll2.createIndex({skey: 1, extra: -1}));
+ assert.commandWorked(coll2.ensureIndex({skey: 1, extra: -1}));
} else if (i == 2) {
- assert.commandWorked(coll2.createIndex({skey: 1, extra: 1, superfluous: -1}));
+ assert.commandWorked(coll2.ensureIndex({skey: 1, extra: 1, superfluous: -1}));
}
// then shard collection on prefix
diff --git a/jstests/sharding/printShardingStatus.js b/jstests/sharding/printShardingStatus.js
index e0439d63bc1..691f627ef72 100644
--- a/jstests/sharding/printShardingStatus.js
+++ b/jstests/sharding/printShardingStatus.js
@@ -115,7 +115,7 @@ config.getCollectionInfos().forEach(function(c) {
delete i.key;
delete i.ns;
delete i.v;
- assert.commandWorked(configCopy.getCollection(c.name).createIndex(key, i));
+ assert.commandWorked(configCopy.getCollection(c.name).ensureIndex(key, i));
});
});
diff --git a/jstests/sharding/query/explain_cmd.js b/jstests/sharding/query/explain_cmd.js
index fb1d789e1db..b07eacbfb3f 100644
--- a/jstests/sharding/query/explain_cmd.js
+++ b/jstests/sharding/query/explain_cmd.js
@@ -12,8 +12,8 @@ var explain;
// 'b'.
var collSharded = db.getCollection("mongos_explain_cmd");
collSharded.drop();
-collSharded.createIndex({a: 1});
-collSharded.createIndex({b: 1});
+collSharded.ensureIndex({a: 1});
+collSharded.ensureIndex({b: 1});
// Enable sharding.
assert.commandWorked(db.adminCommand({enableSharding: db.getName()}));
@@ -65,8 +65,8 @@ assert.commandFailed(explain);
// Setup a collection that is not sharded.
var collUnsharded = db.getCollection("mongos_explain_cmd_unsharded");
collUnsharded.drop();
-collUnsharded.createIndex({a: 1});
-collUnsharded.createIndex({b: 1});
+collUnsharded.ensureIndex({a: 1});
+collUnsharded.ensureIndex({b: 1});
for (var i = 0; i < 3; i++) {
collUnsharded.insert({_id: i, a: i, b: 1});
diff --git a/jstests/sharding/query/explain_exec_stats_on_shards.js b/jstests/sharding/query/explain_exec_stats_on_shards.js
index 253b47a3238..fa2a21864d8 100644
--- a/jstests/sharding/query/explain_exec_stats_on_shards.js
+++ b/jstests/sharding/query/explain_exec_stats_on_shards.js
@@ -98,7 +98,7 @@ st.ensurePrimaryShard(db.getName(), st.shard0.shardName);
// Setup an unsharded collection.
const unshardedColl = db.getCollection(`${jsTest.name()}_unsharded`);
unshardedColl.drop();
- assert.commandWorked(unshardedColl.createIndex({a: 1}));
+ assert.commandWorked(unshardedColl.ensureIndex({a: 1}));
// Add documents to the collection.
const numDocs = 10;
diff --git a/jstests/sharding/query/explain_find_and_modify_sharded.js b/jstests/sharding/query/explain_find_and_modify_sharded.js
index 65f5dc17d6c..a8dad43a201 100644
--- a/jstests/sharding/query/explain_find_and_modify_sharded.js
+++ b/jstests/sharding/query/explain_find_and_modify_sharded.js
@@ -17,7 +17,7 @@ var shardKey = {a: 1};
var shardedColl = testDB.getCollection(collName);
shardedColl.drop();
assert.commandWorked(testDB.createCollection(collName));
-assert.commandWorked(shardedColl.createIndex(shardKey));
+assert.commandWorked(shardedColl.ensureIndex(shardKey));
// Enable sharding on the database and shard the collection.
// Use "st.shard0.shardName" as the primary shard.
diff --git a/jstests/sharding/query/find_getmore_cmd.js b/jstests/sharding/query/find_getmore_cmd.js
index 997d3bb2207..d2dcc311523 100644
--- a/jstests/sharding/query/find_getmore_cmd.js
+++ b/jstests/sharding/query/find_getmore_cmd.js
@@ -25,7 +25,7 @@ assert.commandWorked(coll.insert({_id: 1, a: 5}));
assert.commandWorked(coll.insert({_id: 5, a: 20, b: "foo foo foo"}));
assert.commandWorked(coll.insert({_id: 9, a: 3}));
-assert.commandWorked(coll.createIndex({b: "text"}));
+assert.commandWorked(coll.ensureIndex({b: "text"}));
assert.commandWorked(db.adminCommand({enableSharding: db.getName()}));
st.ensurePrimaryShard(db.getName(), st.shard0.shardName);
diff --git a/jstests/sharding/query/geo_near_sharded.js b/jstests/sharding/query/geo_near_sharded.js
index d68dcdec140..cf09b14a533 100644
--- a/jstests/sharding/query/geo_near_sharded.js
+++ b/jstests/sharding/query/geo_near_sharded.js
@@ -39,7 +39,7 @@ function test(st, db, sharded, indexType) {
assert.commandWorked(bulk.execute());
assert.eq(db[coll].count(), numPts);
- assert.commandWorked(db[coll].createIndex({loc: indexType}));
+ assert.commandWorked(db[coll].ensureIndex({loc: indexType}));
let res = assert.commandWorked(db.runCommand({
aggregate: coll,
diff --git a/jstests/sharding/read_pref_cmd.js b/jstests/sharding/read_pref_cmd.js
index d3ac3f4c03a..3fa06255bfc 100644
--- a/jstests/sharding/read_pref_cmd.js
+++ b/jstests/sharding/read_pref_cmd.js
@@ -307,7 +307,7 @@ let testConnReadPreference = function(conn, isMongos, rsNodes, {readPref, expect
cmdTest(
{dbStats: 1}, allowedOnSecondary.kAlways, true, formatProfileQuery(kDbName, {dbStats: 1}));
- assert.commandWorked(shardedColl.createIndex({loc: '2d'}));
+ assert.commandWorked(shardedColl.ensureIndex({loc: '2d'}));
// TODO: SERVER-38961 Remove when simultaneous index builds complete.
// Run a no-op command and wait for it to be applied on secondaries. Due to the asynchronous
diff --git a/jstests/sharding/refine_shardkey_config_cache_refresh.js b/jstests/sharding/refine_shardkey_config_cache_refresh.js
index 595e4f87cda..9b343353bd3 100644
--- a/jstests/sharding/refine_shardkey_config_cache_refresh.js
+++ b/jstests/sharding/refine_shardkey_config_cache_refresh.js
@@ -22,7 +22,7 @@ assert.commandWorked(st.s.adminCommand({split: 'test.user', middle: {x: 10}}));
assert.commandWorked(testDB.user.insert({x: 1, y: 1}));
assert.commandWorked(testDB.user.insert({x: 10, y: 1}));
-testDB.user.createIndex({x: 1, y: 1});
+testDB.user.ensureIndex({x: 1, y: 1});
let priConn = st.rs0.getPrimary();
assert.commandWorked(
diff --git a/jstests/sharding/shard1.js b/jstests/sharding/shard1.js
index 12f326a32f6..d00a961be52 100644
--- a/jstests/sharding/shard1.js
+++ b/jstests/sharding/shard1.js
@@ -11,7 +11,7 @@ assert.commandWorked(db.foo.insert({num: 1, name: "eliot"}));
assert.commandWorked(db.foo.insert({num: 2, name: "sara"}));
assert.commandWorked(db.foo.insert({num: -1, name: "joe"}));
-assert.commandWorked(db.foo.createIndex({num: 1}));
+assert.commandWorked(db.foo.ensureIndex({num: 1}));
assert.eq(3, db.foo.find().length(), "A");
diff --git a/jstests/sharding/shard7.js b/jstests/sharding/shard7.js
index 9f56553aa7f..094688d6e37 100644
--- a/jstests/sharding/shard7.js
+++ b/jstests/sharding/shard7.js
@@ -47,7 +47,7 @@ assert.commandWorked(c.update(unsatisfiable, {$set: {c: 1}}, false, true));
assert.eq(2, c.count());
assert.eq(0, c.count({c: 1}));
-c.createIndex({loc: '2d'});
+c.ensureIndex({loc: '2d'});
c.save({a: 2, b: 2, loc: [0, 0]});
near =
c.aggregate({$geoNear: {near: [0, 0], query: unsatisfiable, distanceField: "dist"}}).toArray();
diff --git a/jstests/sharding/shard_insert_getlasterror_w2.js b/jstests/sharding/shard_insert_getlasterror_w2.js
index 629b97d321a..9db83bf5781 100644
--- a/jstests/sharding/shard_insert_getlasterror_w2.js
+++ b/jstests/sharding/shard_insert_getlasterror_w2.js
@@ -47,7 +47,7 @@ assert.commandWorked(mongosConn.adminCommand({addshard: replSet1.getURL()}));
// Enable sharding on test db and its collection foo
assert.commandWorked(mongosConn.getDB('admin').runCommand({enablesharding: testDBName}));
-testDB[testCollName].createIndex({x: 1});
+testDB[testCollName].ensureIndex({x: 1});
assert.commandWorked(mongosConn.getDB('admin').runCommand(
{shardcollection: testDBName + '.' + testCollName, key: {x: 1}}));
diff --git a/jstests/sharding/sharding_rs1.js b/jstests/sharding/sharding_rs1.js
index 02b5e13b213..61fe245d75b 100644
--- a/jstests/sharding/sharding_rs1.js
+++ b/jstests/sharding/sharding_rs1.js
@@ -52,7 +52,7 @@ assert.eq(num, db.foo.find().itcount(), "C2");
assert.eq(num, db.foo.find().sort({_id: 1}).itcount(), "C3");
assert.eq(num, db.foo.find().sort({_id: -1}).itcount(), "C4");
-db.foo.createIndex({x: 1});
+db.foo.ensureIndex({x: 1});
assert.eq(num, db.foo.find().sort({x: 1}).itcount(), "C5");
assert.eq(num, db.foo.find().sort({x: -1}).itcount(), "C6");
diff --git a/jstests/sharding/sharding_rs2.js b/jstests/sharding/sharding_rs2.js
index 4c8f70c569d..8ae4a16185b 100644
--- a/jstests/sharding/sharding_rs2.js
+++ b/jstests/sharding/sharding_rs2.js
@@ -122,7 +122,7 @@ assert.lte(before.query + 10, after.query, "B3");
// --- add more data ----
-db.foo.createIndex({x: 1});
+db.foo.ensureIndex({x: 1});
var bulk = db.foo.initializeUnorderedBulkOp();
for (var i = 0; i < 100; i++) {
diff --git a/jstests/sharding/stats.js b/jstests/sharding/stats.js
index f69aefc6825..0f9f00a667c 100644
--- a/jstests/sharding/stats.js
+++ b/jstests/sharding/stats.js
@@ -144,7 +144,7 @@ collStatComp(coll_not_scaled, coll_scaled_1024, 1024, true);
(function() {
var t = db.foo;
-assert.commandWorked(t.createIndex({a: 1}));
+assert.commandWorked(t.ensureIndex({a: 1}));
assert.eq(2, t.getIndexes().length);
var isWiredTiger =
diff --git a/jstests/sharding/trace_missing_docs_test.js b/jstests/sharding/trace_missing_docs_test.js
index 460f392e1c8..ab7b1c058a8 100644
--- a/jstests/sharding/trace_missing_docs_test.js
+++ b/jstests/sharding/trace_missing_docs_test.js
@@ -20,7 +20,7 @@ var testDocMissing = function(useReplicaSet) {
assert.commandWorked(admin.runCommand({enableSharding: coll.getDB() + ""}));
st.ensurePrimaryShard(coll.getDB() + "", st.shard0.shardName);
- coll.createIndex({sk: 1});
+ coll.ensureIndex({sk: 1});
assert.commandWorked(admin.runCommand({shardCollection: coll + "", key: {sk: 1}}));
assert.commandWorked(coll.insert({_id: 12345, sk: 67890, hello: "world"}));
diff --git a/jstests/slow1/conc_update.js b/jstests/slow1/conc_update.js
index 0ca9ea81bea..80adb4955e4 100644
--- a/jstests/slow1/conc_update.js
+++ b/jstests/slow1/conc_update.js
@@ -16,7 +16,7 @@ for (var i = 0; i < NRECORDS; i++) {
assert.commandWorked(bulk.execute());
print("making an index (this will take a while)");
-db.conc.createIndex({x: 1});
+db.conc.ensureIndex({x: 1});
var c1 = db.conc.count({x: {$lt: NRECORDS}});
diff --git a/src/mongo/shell/collection.js b/src/mongo/shell/collection.js
index 2043fcfbe74..ff218371d39 100644
--- a/src/mongo/shell/collection.js
+++ b/src/mongo/shell/collection.js
@@ -66,6 +66,8 @@ DBCollection.prototype.help = function() {
".unhideIndex( \"indexName\" ) or db." + shortName +
".unhideIndex( { \"indexKey\" : 1 } )");
print("\tdb." + shortName + ".dropIndexes()");
+ print("\tdb." + shortName +
+ ".ensureIndex(keypattern[,options]) - DEPRECATED, use createIndex() instead");
print("\tdb." + shortName + ".explain().help() - show explain help");
print("\tdb." + shortName + ".reIndex()");
print(
@@ -685,6 +687,24 @@ DBCollection.prototype.createIndexes = function(keys, options, commitQuorum) {
{createIndexes: this.getName(), indexes: indexSpecs, commitQuorum: commitQuorum});
};
+DBCollection.prototype.ensureIndex = function(keys, options) {
+ if (arguments.length > 2) {
+ throw new Error("ensureIndex accepts up to 2 arguments");
+ }
+
+ var result = this.createIndex(keys, options);
+
+ if (this.getMongo().writeMode() != "legacy") {
+ return result;
+ }
+
+ err = this.getDB().getLastErrorObj();
+ if (err.err) {
+ return err;
+ }
+ // nothing returned on success
+};
+
DBCollection.prototype.reIndex = function() {
return this._db.runCommand({reIndex: this.getName()});
};