Permalink
Browse files

Fixed a bug in query parsing that would give a duplicate key error wh…

…en comparing the same field twice.
  • Loading branch information...
1 parent 337cda3 commit 1fdaeb65932bdac8fa8dd007c2bf99e666edd5d9 Samuel Corder committed Dec 16, 2009
Showing with 17 additions and 5 deletions.
  1. +1 −1 .gitignore
  2. +10 −2 MongoDB.Linq.Tests/TestQueryParsing.cs
  3. +6 −2 MongoDB.Linq/MongoQueryTranslator.cs
View
@@ -24,4 +24,4 @@ obj/*
MongoDB.Linq/obj/*
MongoDB.Linq.Tests/bin/*
MongoDB.Linq.Tests/obj/*
-
+MongoDB.Linq.Tests/test-results/*
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Diagnostics;
using System.Linq;
using MongoDB.Driver;
@@ -192,7 +192,15 @@ public class TestQueryParsing {
.Append("bar","zoop"),
q.Query);
}
-
+
+ [Test]
+ public void Can_do_and_queries_on_same_key(){
+ var q = (IMongoQuery)(from d in queryable where (int)d["foo"] < 10 && (int)d["foo"] > 5 select d);
+ Assert.AreEqual(
+ new Document().Append("foo", new Document().Append("$lt", 10).Append("$gt",5)),
+ q.Query);
+ }
+
[Test]
public void Can_compose_queries() {
// Note (sdether): this passes without explicit AND support, which is a bit scary
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
@@ -231,7 +231,11 @@ public class MongoQueryTranslator : ExpressionVisitor {
case ExpressionType.GreaterThan: conditional = reverseConditional ? "$lt" : "$gt"; break;
case ExpressionType.GreaterThanOrEqual: conditional = reverseConditional ? "$lte" : "$gte"; break;
}
- Query.Append(key, new Document().Append(conditional, value));
+ if(Query.Contains(key)){
+ ((Document)Query[key]).Append(conditional,value);
+ }else{
+ Query.Append(key, new Document().Append(conditional, value));
+ }
inConditional = false;
foundKey = false;
break;

0 comments on commit 1fdaeb6

Please sign in to comment.