public async Task <IActionResult> Find(string clusterId, string dbName, string collectionName,
                                               [FromBody] MongoFindRequest body)
        {
            var findCursor = await FindInternal(clusterId, dbName, collectionName, body);

            var aggregate = await findCursor.ToListAsync();

            var result = aggregate.Select(a => a.ToJObject()).ToList();

            return(Ok(result));
        }
        public async Task <IActionResult> FindObject(string clusterId, string dbName, string collectionName,
                                                     [FromBody] MongoFindRequest body)
        {
            var findCursor = await FindInternal(clusterId, dbName, collectionName, body);

            var resultBson = await findCursor.SingleOrDefaultAsync();

            if (resultBson == null)
            {
                return(NotFound());
            }

            return(Ok(resultBson.ToJObject()));
        }
        private async Task <IAsyncCursor <BsonDocument> > FindInternal(
            string clusterId, string dbName, string collectionName, MongoFindRequest body)
        {
            var collection = _configuration.GetCollection(clusterId, dbName, collectionName);
            var filter     = body.Filter.ToBsonDocument().Preprocess();
            var sort       = body.Sort.ToBsonDocument();
            var projection = body.Projection.ToBsonDocument().Preprocess();

            var findOptions = new FindOptions <BsonDocument, BsonDocument>()
            {
                Limit      = body.Limit,
                Skip       = body.Skip,
                Sort       = sort,
                Projection = projection
            };

            return(await collection.FindAsync(filter, findOptions));
        }