MongoDB.Driver.Builders.DeprecatedQuery.ElemMatch C# (CSharp) Method

ElemMatch() public static method

Tests that at least one item of the named array element matches a query (see $elemMatch).
public static ElemMatch ( string name, IMongoQuery query ) : QueryConditionList
name string The name of the element to test.
query IMongoQuery The query to match elements with.
return QueryConditionList
        public static QueryConditionList ElemMatch(string name, IMongoQuery query)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            return new QueryConditionList(name).ElemMatch(query);
        }

Usage Example

        public void TestElementMatch()
        {
            var query = Query.ElemMatch("x",
                                        Query.And(
                                            Query.EQ("a", 1),
                                            Query.GT("b", 1)
                                            )
                                        );
            var expected = "{ \"x\" : { \"$elemMatch\" : { \"a\" : 1, \"b\" : { \"$gt\" : 1 } } } }";

            Assert.AreEqual(expected, query.ToJson());
        }