private CommandResult CreateView(IClientSessionHandle session, string viewName, string viewOn, IEnumerable <BsonDocument> pipeline, IMongoCreateViewOptions options)
        {
            if (viewName == null)
            {
                throw new ArgumentNullException(nameof(viewName));
            }
            if (viewOn == null)
            {
                throw new ArgumentNullException(nameof(viewOn));
            }
            if (pipeline == null)
            {
                throw new ArgumentNullException(nameof(pipeline));
            }

            Collation collation = null;

            if (options != null)
            {
                var optionsDocument = options.ToBsonDocument();

                BsonValue value;
                if (optionsDocument.TryGetValue("collation", out value))
                {
                    collation = Collation.FromBsonDocument(value.AsBsonDocument);
                }
            }

            var operation = new CreateViewOperation(_namespace, viewName, viewOn, pipeline, GetMessageEncoderSettings())
            {
                Collation    = collation,
                WriteConcern = _settings.WriteConcern
            };

            var response = ExecuteWriteOperation(session, operation);

            return(new CommandResult(response));
        }
 /// <summary>
 /// Creates a view.
 /// </summary>
 /// <param name="viewName">The name of the view.</param>
 /// <param name="viewOn">The name of the collection that the view is on.</param>
 /// <param name="pipeline">The pipeline.</param>
 /// <param name="options">The options.</param>
 /// <returns>A CommandResult.</returns>
 public virtual CommandResult CreateView(string viewName, string viewOn, IEnumerable <BsonDocument> pipeline, IMongoCreateViewOptions options)
 {
     return(UsingImplicitSession(session => CreateView(session, viewName, viewOn, pipeline, options)));
 }