コード例 #1
0
        public async Task FindInDatabase([Summary("Database to query.")] string dbName,
                                         [Summary("Collection to query.")] string collectionName,
                                         [Summary("Field to query.")] string field,
                                         [Summary("Type of field to query.")] BasicType type,
                                         [Summary("Value to match against.")] string value,
                                         [Summary("How many values to include at most.")] int limit = 1,
                                         [Summary("How many values to skip.")] int skip             = 0)
        {
            var collection = await GetCollection <BsonDocument>(dbName, collectionName);

            if (collection == null)
            {
                return;
            }
            if (!type.TryParseValue(value, out object parsedValue))
            {
                await Error($"Failed to parse {value} as {type}.");

                return;
            }
            var query = await collection.Find(
                Builders <BsonDocument> .Filter.Eq(field, parsedValue)
                ).Limit(limit).Skip(skip).ToCursorAsync();

            await QueryResult <BsonDocument>("Query result", query);
        }