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); if (CoreTestConfiguration.ServerVersion >= new SemanticVersion(4, 5, 0, "")) { index["wildcardProjection"].Should().Be(BsonDocument.Parse("{ _id : true }")); } else { index["wildcardProjection"].Should().Be(BsonDocument.Parse("{ _id : 1 }")); } }
public void WildcardProjection_should_return_expected_result() { var options = IndexOptions.SetWildcardProjection("a", true); BsonDocument expected = BsonDocument.Parse("{ \"wildcardProjection\" : { \"a\" : 1 } }"); options.ToBsonDocument().Should().Be(expected); options = IndexOptions.SetWildcardProjection("a.b", true).SetWildcardProjection("_id", false); expected = BsonDocument.Parse("{ \"wildcardProjection\" : { \"a.b\" : 1, \"_id\" : 0} }"); options.ToBsonDocument().Should().Be(expected); }
public void WildcardProjection_should_return_expected_result() { var options = IndexOptions <TestClass> .SetWildcardProjection(x => x.textfield, true); BsonDocument expected = BsonDocument.Parse("{ \"wildcardProjection\" : { \"textfield\" : 1 } }"); options.ToBsonDocument().Should().Be(expected); options = IndexOptions <TestClass> .SetWildcardProjection(x => x._id, false) .SetWildcardProjection(x => x.details.text, true); expected = BsonDocument.Parse("{ \"wildcardProjection\" : { \"_id\" : 0, \"details.text\" : 1 } }"); options.ToBsonDocument().Should().Be(expected); }