public void CreateIndex_with_wildcardProjection_should_create_expected_index() { RequireServer.Check().Supports(Feature.WildcardIndexes); var collection = _database.GetCollection <Test>("test_wildcard_index"); collection.Drop(); collection.CreateIndex( IndexKeys <Test> .Wildcard(), IndexOptions <Test> .SetName("custom") .SetWildcardProjection(c => c.B, true) .SetWildcardProjection(c => c.Id, false)); var indexes = collection.GetIndexes(); var index = indexes.RawDocuments.Single(i => i["name"].AsString == "custom"); index["key"]["$**"].AsInt32.Should().Be(1); if (CoreTestConfiguration.ServerVersion >= new SemanticVersion(4, 5, 0, "")) { index["wildcardProjection"].Should().Be(BsonDocument.Parse("{ b : true, _id : false }")); } else { index["wildcardProjection"].Should().Be(BsonDocument.Parse("{ b : 1, _id : 0 }")); } }
public void Wildcard_should_return_expected_result() { var keys = IndexKeys.Wildcard(); BsonDocument expected = BsonDocument.Parse("{ \"$**\" : 1 }"); keys.ToBsonDocument().Should().Be(expected); keys = IndexKeys.Wildcard("b"); expected = BsonDocument.Parse("{ \"b.$**\" : 1 }"); keys.ToBsonDocument().Should().Be(expected); }
public void Wildcard_index_should_return_expected_result() { var keys = IndexKeys <Test> .Wildcard(); BsonDocument expected = BsonDocument.Parse("{ \"$**\" : 1 }"); keys.ToBsonDocument().Should().Be(expected); keys = IndexKeys <Test> .Wildcard(x => x.A); expected = BsonDocument.Parse("{ \"a.$**\" : 1 }"); keys.ToBsonDocument().Should().Be(expected); }
public void CreateIndex_with_wildcard_index_should_create_expected_index() { RequireServer.Check().Supports(Feature.WildcardIndexes); var collection = _database.GetCollection <Test>("test_wildcard_index"); collection.Drop(); collection.CreateIndex( IndexKeys <Test> .Wildcard(c => c.A), IndexOptions.SetName("custom")); var indexes = collection.GetIndexes(); var index = indexes.RawDocuments.Single(i => i["name"].AsString == "custom"); index["key"]["a.$**"].AsInt32.Should().Be(1); }
public void CreateIndex_with_wildcardProjection_should_create_expected_index() { RequireServer.Check().Supports(Feature.WildcardIndexes); var collection = _database.GetCollection <BsonDocument>("test_wildcard_index"); collection.Drop(); collection.CreateIndex( IndexKeys.Wildcard(), // wildcardProjection can be only with '$**' IndexOptions .SetWildcardProjection("_id", true) .SetName("custom")); var indexes = collection.GetIndexes(); var index = indexes.RawDocuments.Single(i => i["name"].AsString == "custom"); index["key"]["$**"].AsInt32.Should().Be(1); index["wildcardProjection"].Should().Be(BsonDocument.Parse("{ _id : 1 }")); }