Example #1
0
        public void Should_Save_Multiple_Documents()
        {
            var pets = new Documents();

            pets.Values.Add(new Document(@"{ ""name"": ""Santa's Little Helper"" }"));
            pets.Values.Add(new Document(@"{ ""name"": ""Snowball V"" }"));
            pets.Values.Add(new Document(@"{ ""name"": ""Strangles"" }"));

            db.SaveDocuments(pets, true);
        }
        public BulkResponse Execute()
        {
            // This method divid the update to chunks because services such as Cloudant
            // recommend to limit the number of bulk documents to around 500 docs.

            List <BulkResponseRow> responses = new List <BulkResponseRow>(docsToUpdate.Count);

            foreach (JObject[] updateChunk in docsToUpdate.Chunks(BulkChunkSize))
            {
                Documents docs = new Documents();
                docs.Values.AddRange(updateChunk.Select(x => new Document(x)));

                BulkDocumentResponses         bulkResponse         = couchDB.SaveDocuments(docs, allOrNothing);
                IEnumerable <BulkResponseRow> abstractResponseRows =
                    bulkResponse.Select(x => new BulkResponseRow(x.Id, x.Rev, x.Error, x.Reason));

                responses.AddRange(abstractResponseRows);
            }


            return(new BulkResponse(responses.ToArray()));
        }