Skip to content

Commit 5c60890

Browse files
author
rstam
committed
Minor changes during code review of query builders, primarily added checking for null arguments and changed Matches method to have a single overload with a BsonRegularExpression parameter.
1 parent 8f4dc64 commit 5c60890

File tree

5 files changed

+165
-51
lines changed

5 files changed

+165
-51
lines changed

Driver/Builders/QueryBuilder.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using System.Collections.Generic;
1818
using System.Linq;
1919
using System.Text;
20-
using System.Text.RegularExpressions;
2120

2221
using MongoDB.Bson;
2322

@@ -353,6 +352,11 @@ public static IMongoQuery Near(string name, double x, double y, double maxDistan
353352
/// <returns>An IMongoQuery.</returns>
354353
public static IMongoQuery Not(IMongoQuery query)
355354
{
355+
if (query == null)
356+
{
357+
throw new ArgumentNullException("query");
358+
}
359+
356360
var queryDocument = query.ToBsonDocument();
357361
if (queryDocument.ElementCount == 1)
358362
{
@@ -428,6 +432,15 @@ public static IMongoQuery Not(IMongoQuery query)
428432
/// <returns>An IMongoQuery.</returns>
429433
public static IMongoQuery NE(string name, BsonValue value)
430434
{
435+
if (name == null)
436+
{
437+
throw new ArgumentNullException("name");
438+
}
439+
if (value == null)
440+
{
441+
throw new ArgumentNullException("value");
442+
}
443+
431444
return new QueryDocument(name, new BsonDocument("$ne", value));
432445
}
433446

@@ -438,6 +451,11 @@ public static IMongoQuery NE(string name, BsonValue value)
438451
/// <returns>An IMongoQuery.</returns>
439452
public static IMongoQuery NotExists(string name)
440453
{
454+
if (name == null)
455+
{
456+
throw new ArgumentNullException("name");
457+
}
458+
441459
return new QueryDocument(name, new BsonDocument("$exists", false));
442460
}
443461

@@ -449,6 +467,15 @@ public static IMongoQuery NotExists(string name)
449467
/// <returns>An IMongoQuery.</returns>
450468
public static IMongoQuery NotIn(string name, IEnumerable<BsonValue> values)
451469
{
470+
if (name == null)
471+
{
472+
throw new ArgumentNullException("name");
473+
}
474+
if (values == null)
475+
{
476+
throw new ArgumentNullException("values");
477+
}
478+
452479
return new QueryDocument(name, new BsonDocument("$nin", new BsonArray(values)));
453480
}
454481

0 commit comments

Comments
 (0)