Skip to content

Instantly share code, notes, and snippets.

@zgramana
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zgramana/8bedff3558774b922ac6 to your computer and use it in GitHub Desktop.
Save zgramana/8bedff3558774b922ac6 to your computer and use it in GitHub Desktop.
Simple first script to create a bunch of docs and replicate them.
// Run `scriptcs -install Couchbase.Lite` to fetch Couchbase Lite from Nuget.
#r Couchbase.Lite.dll
using Couchbase.Lite;
var db = Manager.SharedInstance.GetDatabase("scriptcs");
db.RunInTransaction(()=>
{
for (var i = 0; i < 10000; i++)
{
if (db.DocumentCount > 10000)
{
db.Delete();
break;
}
db.CreateDocument()
.PutProperties(new Dictionary<string,object>{ {"foo", i} });
if ((i % 100) == 0)
{
Console.WriteLine("DB: {0}, {1} total docs, {2} max sequence number", db.Name, db.DocumentCount, db.LastSequenceNumber);
}
}
return true;
});
var replication = db.CreatePushReplication(new Uri("http://localhost:4984/db/"));
replication.Changed += (sender, e) =>
{
Console.WriteLine("Replication: {0} total changes, {1} completed changes", e.Source.ChangesCount, e.Source.CompletedChangesCount);
};
replication.Start();
Console.WriteLine("Press any key to quit...");
Console.ReadKey();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment