diff --git a/LiteDB/Database/Collections/Aggregate.cs b/LiteDB/Database/Collections/Aggregate.cs
index 26c4db9ac..03632e859 100644
--- a/LiteDB/Database/Collections/Aggregate.cs
+++ b/LiteDB/Database/Collections/Aggregate.cs
@@ -74,41 +74,22 @@ public bool Exists(Query query)
///
/// Returns the first/min value from a index field
///
- public BsonValue Min(string field)
- {
- if (string.IsNullOrEmpty(field)) throw new ArgumentNullException(nameof(field));
-
- return _engine.Value.Min(_name, field);
- }
-
- ///
- /// Returns the first/min _id field
- ///
public BsonValue Min()
{
- return this.Min("_id");
+ return _engine.Value.Min(_name);
}
-
///
/// Returns the last/max value from a index field
///
- public BsonValue Max(string field)
- {
- if (string.IsNullOrEmpty(field)) throw new ArgumentNullException(nameof(field));
-
- return _engine.Value.Max(_name, field);
- }
-
- ///
- /// Returns the last/max _id field
- ///
public BsonValue Max()
{
- return this.Max("_id");
+ return _engine.Value.Max(_name);
}
+
+
#endregion
}
}
\ No newline at end of file
diff --git a/LiteDB/Engine/Engine/Aggregate.cs b/LiteDB/Engine/Engine/Aggregate.cs
index d78e1248a..82fd511a4 100644
--- a/LiteDB/Engine/Engine/Aggregate.cs
+++ b/LiteDB/Engine/Engine/Aggregate.cs
@@ -8,10 +8,9 @@ public partial class LiteEngine
///
/// Returns first value from an index (first is min value)
///
- public BsonValue Min(string collection, string field)
+ public BsonValue Min(string collection)
{
if (collection.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(collection));
- if (field.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(field));
var col = this.GetCollectionPage(collection, false);
@@ -19,7 +18,7 @@ public BsonValue Min(string collection, string field)
if (col == null) return BsonValue.MinValue;
// get index (no index, no min)
- var index = col.GetIndex(field);
+ var index = col.PK;
if (index == null) return BsonValue.MinValue;
@@ -35,18 +34,16 @@ public BsonValue Min(string collection, string field)
///
/// Returns last value from an index (last is max value)
///
- public BsonValue Max(string collection, string field)
+ public BsonValue Max(string collection)
{
if (collection.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(collection));
- if (field.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(field));
-
var col = this.GetCollectionPage(collection, false);
if (col == null) return BsonValue.MaxValue;
// get index (no index, no max)
- var index = col.GetIndex(field);
+ var index = col.PK;
if (index == null) return BsonValue.MaxValue;
diff --git a/LiteDB/Engine/Engine/Insert.cs b/LiteDB/Engine/Engine/Insert.cs
index 423291677..eb58dab2f 100644
--- a/LiteDB/Engine/Engine/Insert.cs
+++ b/LiteDB/Engine/Engine/Insert.cs
@@ -72,7 +72,7 @@ private void InsertDocument(CollectionPage col, BsonDocument doc, BsonType autoI
// ** this code can be removed when datafile change from 7 (HeaderPage.FILE_VERSION) **
if (col.Sequence == 0 && col.DocumentCount > 0)
{
- var max = this.Max(col.CollectionName, "_id");
+ var max = this.Max(col.CollectionName);
// if max value is a number, convert to Sequence last value
// if not, just set sequence as document count
diff --git a/LiteDB/Engine/Pages/CollectionPage.cs b/LiteDB/Engine/Pages/CollectionPage.cs
index aefdd7007..f1e408b06 100644
--- a/LiteDB/Engine/Pages/CollectionPage.cs
+++ b/LiteDB/Engine/Pages/CollectionPage.cs
@@ -151,21 +151,11 @@ protected override void WriteContent(ByteWriter writer)
///
public CollectionIndex GetFreeIndex()
{
- for (byte i = 0; i < this.Indexes.Length; i++)
- {
- if (this.Indexes[i].IsEmpty) return this.Indexes[i];
- }
+ if (this.Indexes[0].IsEmpty) return this.Indexes[0];
throw LiteException.IndexLimitExceeded(this.CollectionName);
}
- ///
- /// Get index from field name (index field name is case sensitive) - returns null if not found
- ///
- public CollectionIndex GetIndex(string field)
- {
- return this.Indexes.FirstOrDefault(x => x.Field == field);
- }
///
/// Get primary key index (_id index)