|
1 | 1 | using System; |
2 | 2 | using System.Configuration; |
3 | 3 | using System.Threading; |
| 4 | +using System.Linq; |
4 | 5 | using MongoDB.Bson; |
5 | 6 | using MongoDB.Driver; |
6 | 7 | using System.Reflection; |
7 | 8 | using System.Security.Cryptography; |
8 | 9 |
|
9 | | -[assembly: AssemblyVersion("1.2.0.*")] |
| 10 | +[assembly: AssemblyVersion("1.2.1.*")] |
10 | 11 |
|
11 | 12 | namespace DominionEnterprises.Mongo |
12 | 13 | { |
@@ -103,6 +104,7 @@ public void EnsureGetIndex(IndexKeysDocument beforeSort, IndexKeysDocument after |
103 | 104 |
|
104 | 105 | /// <summary> |
105 | 106 | /// Ensure index for Count() method |
| 107 | + /// Is a no-op if the generated index is a prefix of an existing one. If you have a similar EnsureGetIndex call, call it first. |
106 | 108 | /// </summary> |
107 | 109 | /// <param name="index">fields in Count() call</param> |
108 | 110 | /// <param name="includeRunning">whether running was given to Count() or not</param> |
@@ -491,6 +493,18 @@ public void Send(BsonDocument payload, DateTime earliestGet, double priority) |
491 | 493 |
|
492 | 494 | private void EnsureIndex(IndexKeysDocument index) |
493 | 495 | { |
| 496 | + //if index is a prefix of any existing index we are good |
| 497 | + foreach (var existingIndex in collection.GetIndexes()) |
| 498 | + { |
| 499 | + var names = index.Names; |
| 500 | + var values = index.Values; |
| 501 | + var existingNamesPrefix = existingIndex.Key.Names.Take(names.Count()); |
| 502 | + var existingValuesPrefix = existingIndex.Key.Values.Take(values.Count()); |
| 503 | + |
| 504 | + if (Enumerable.SequenceEqual(names, existingNamesPrefix) && Enumerable.SequenceEqual(values, existingValuesPrefix)) |
| 505 | + return; |
| 506 | + } |
| 507 | + |
494 | 508 | for (var i = 0; i < 5; ++i) |
495 | 509 | { |
496 | 510 | for (var name = Guid.NewGuid().ToString(); name.Length > 0; name = name.Substring(0, name.Length - 1)) |
|
0 commit comments