Exemplo n.º 1
0
 public override IAsyncCursor <TResult> ToCursor(CancellationToken cancellationToken)
 {
     if (_session == null)
     {
         return(_database.Aggregate(_pipeline, _options, cancellationToken));
     }
     else
     {
         return(_database.Aggregate(_session, _pipeline, _options, cancellationToken));
     }
 }
Exemplo n.º 2
0
        public IAsyncCursor <TResult> Aggregate <TResult>(
            PipelineDefinition <NoPipelineInput, TResult> pipeline,
            AggregateOptions?options            = null,
            CancellationToken cancellationToken = default)
        {
            if (TryGetSession(out IClientSessionHandle? session))
            {
                return(Aggregate(session, pipeline, options, cancellationToken));
            }

            return(_database.Aggregate(pipeline, options, cancellationToken));
        }
Exemplo n.º 3
0
 protected override List <BsonDocument> ExecuteAndGetResult(IMongoDatabase database, IMongoCollection <BsonDocument> collection, bool async)
 {
     if (collection == null)
     {
         if (async)
         {
             var cursor = database.AggregateAsync <BsonDocument>(_stages, _options).GetAwaiter().GetResult();
             return(cursor.ToListAsync().GetAwaiter().GetResult());
         }
         else
         {
             return(database.Aggregate <BsonDocument>(_stages, _options).ToList());
         }
     }
     else
     {
         if (async)
         {
             var cursor = collection.AggregateAsync <BsonDocument>(_stages, _options).GetAwaiter().GetResult();
             return(cursor.ToListAsync().GetAwaiter().GetResult());
         }
         else
         {
             return(collection.Aggregate <BsonDocument>(_stages, _options).ToList());
         }
     }
 }
        public OperationResult Execute(CancellationToken cancellationToken)
        {
            try
            {
                var cursor = _database.Aggregate(_pipeline, _options, cancellationToken);
                var result = cursor.ToList();

                return(OperationResult.FromResult(new BsonArray(result)));
            }
            catch (Exception exception)
            {
                return(OperationResult.FromException(exception));
            }
        }
Exemplo n.º 5
0
        private void ClearInsertOperations()
        {
            List <BsonDocument> agg = admin.Aggregate()
                                      .AppendStage <BsonDocument>(new BsonDocument
            {
                {
                    "$currentOp",
                    new BsonDocument
                    {
                        { "allUsers", true },
                        { "localOps", true }
                    }
                }
            }).AppendStage <BsonDocument>(new BsonDocument
            {
                { "$match",
                  new BsonDocument
                  {
                      { "op", "insert" },
                  } }
            })
                                      .ToList();

            var values = agg.Select(x => x.GetValue("opid")).ToList();

            values.ForEach(async opId =>
            {
                var opid = values[0].AsInt32;
                var doc  = new Dictionary <string, object>()
                {
                    { "killOp", 1 },
                    { "op", opid }
                };
                var bs         = new BsonDocument(doc);
                BsonDocument s = await admin.RunCommandAsync <BsonDocument>(bs);
            });
        }