void run() { auto opCtx = cc().makeOperationContext(); DBDirectClient client(opCtx.get()); client.dropCollection(_ns); IndexSpec indexSpec; indexSpec.addKey("a"); client.createIndex(_ns, indexSpec); client.insert(_ns, BSON("a" << BSONSymbol("mySymbol"))); ASSERT(client.getLastError().empty()); ASSERT_EQUALS(client.count(_ns), 1U); }
TEST(Options, RepeatedKeysFail) { IndexSpec spec; spec.addKey("aField"); ASSERT_UASSERTS(spec.addKey("aField")); const BSONObj fields = BSON("someField" << 1 << "aField" << 1 << "anotherField" << 1); ASSERT_UASSERTS(spec.addKey(fields.getField("aField"))); ASSERT_UASSERTS(spec.addKeys(fields)); }
void run() { auto opCtx = cc().makeOperationContext(); DBDirectClient client(opCtx.get()); client.dropCollection(_ns); client.insert(_ns, BSON("a" << BSON_ARRAY(99 << BSONSymbol("mySymbol")))); ASSERT_EQUALS(client.count(_ns), 1U); IndexSpec indexSpec; indexSpec.addKey("a").addOptions(BSON("collation" << BSON("locale" << "fr"))); ASSERT_THROWS_CODE(client.createIndex(_ns, indexSpec), AssertionException, ErrorCodes::CannotBuildIndexKeys); }
void run() { auto opCtx = cc().makeOperationContext(); DBDirectClient client(opCtx.get()); client.dropCollection(_ns); IndexSpec indexSpec; indexSpec.addKey("a").addOptions(BSON("collation" << BSON("locale" << "fr"))); client.createIndex(_ns, indexSpec); client.insert(_ns, BSON("a" << BSON_ARRAY(99 << BSONSymbol("mySymbol")))); ASSERT_EQUALS(client.getLastErrorDetailed()["code"].numberInt(), ErrorCodes::CannotBuildIndexKeys); ASSERT_EQUALS(client.count(_ns), 0U); }
Status ShardLocal::createIndexOnConfig(OperationContext* txn, const NamespaceString& ns, const BSONObj& keys, bool unique) { invariant(ns.db() == "config" || ns.db() == "admin"); try { DBDirectClient client(txn); IndexSpec index; index.addKeys(keys); index.unique(unique); client.createIndex(ns.toString(), index); } catch (const DBException& e) { return e.toStatus(); } return Status::OK(); }
void run() { auto opCtx = cc().makeOperationContext(); DBDirectClient client(opCtx.get()); client.dropCollection(_ns); BSONObj cmdResult; ASSERT_TRUE(client.runCommand("unittests", BSON("create" << "indexupdate" << "collation" << BSON("locale" << "fr")), cmdResult)); IndexSpec indexSpec; indexSpec.addKey("a"); client.createIndex(_ns, indexSpec); client.insert(_ns, BSON("a" << BSON_ARRAY(99 << BSONSymbol("mySymbol")))); ASSERT_EQUALS(client.getLastErrorDetailed()["code"].numberInt(), ErrorCodes::CannotBuildIndexKeys); }
TEST(Options, NameIsHonored) { IndexSpec spec; spec.addKey("aField"); // Should get an auto generated name ASSERT_FALSE(spec.name().empty()); // That is not the name we are about to set. ASSERT_NE("someName", spec.name()); spec.name("someName"); // Should get the name we specified. ASSERT_EQ("someName", spec.name()); // Name can be changed as many times as we want spec.name("yetAnotherName"); ASSERT_EQ("yetAnotherName", spec.name()); }
void SchemaDumper::dumpIndex (QStringList &output, const IndexSpec &index) { output << qnotr (" - name: \"%1\"").arg (index.getName ()); output << qnotr (" columns: \"%1\"").arg (index.getColumns ()); }