Exemplo n.º 1
0
            /// <summary>
            /// Finds the first document in the collection that satisfies the query criteria.
            /// </summary>
            /// <param name="filter">
            /// A document describing the find criteria using <see href="https://docs.mongodb.com/manual/reference/operator/query/">query operators</see>.
            /// If not specified, all documents in the collection will match the request.
            /// </param>
            /// <param name="sort">A document describing the sort criteria. If not specified, the order of the returned documents is not guaranteed.</param>
            /// <param name="projection">
            /// A document describing the fields to return for all matching documents. If not specified, all fields are returned.
            /// </param>
            /// <returns>
            /// An awaitable <see cref="Task{T}"/> representing the remote find one operation. The result of the task is the first document that matches the find criteria.
            /// </returns>
            /// <seealso href="https://docs.mongodb.com/manual/reference/method/db.collection.findOne/"/>
            public async Task <TDocument> FindOneAsync(object filter = null, object sort = null, object projection = null)
            {
                var result = await _handle.FindOne(filter?.ToNativeJson(), FindAndModifyOptions.Find(projection, sort));

                return(result.GetValue <TDocument>());
            }