bool DoLast() { if (Last <= 0) { return(false); } Skip = (int)(TargetCollection.Count(_Query) - Skip - Last); First = Last; if (Skip >= 0) { return(false); } First += Skip; if (First <= 0) { if (Count) { WriteObject(0); } return(true); } Skip = 0; return(false); }
protected override void BeginProcessing() { if (First > 0 && Last > 0) { throw new PSArgumentException("Parameters First and Last cannot be specified together."); } try { switch (ParameterSetName) { case nsCount: if (First > 0 || Skip > 0 || Last > 0) { break; } WriteObject(TargetCollection.Count(_Query)); return; case nsDistinct: DoDistinct(); return; case nsRemove: DoRemove(); return; case nsUpdate: DoUpdate(); return; } // Last -> First and Skip if (DoLast()) { return; } // Count if (Count) { WriteObject(TargetCollection.Count(_Query, Skip, First)); return; } //_131018_160000 Do not use WriteObject(.., true), that seems to take a lot more memory foreach (var document in TargetCollection.FindAs(DocumentType, _Query, Modes, _SortBy, Skip, First, _Fields)) { WriteObject(document); } } catch (MongoException ex) { WriteException(ex, null); } }