c# - 在 C# 控制台应用程序中使用 syncgateway 将数据从 Couchbase 服务器拉到 coubase lite
问题描述
我正在尝试在 .Net(Windows 机器)中创建一个简单的控制台应用程序来连接
couchbase lite -> sync-gateway -> couchbase 服务器(托管在远程机器上)。
但数据不会从服务器拉到精简版。
这是我正在使用的示例代码 -
class Program
{
static void Main(string argss)
{
// Get the database (and create it if it doesn't exist)
var database = new Database("testdb");
// Create replicator to push and pull changes to and from the cloud
var targetEndpoint = new URLEndpoint(new Uri("ws://localhost:4984/testdb"));
var replConfig = new ReplicatorConfiguration(database, targetEndpoint);
// Add authentication
replConfig.Authenticator = new BasicAuthenticator("System", "welcome");
// Create replicator (make sure to add an instance or static variable
// named _Replicator)
Replicator _Replicator = new Replicator(replConfig);
_Replicator.AddChangeListener((sender, args) =>
{
if (args.Status.Error != null)
{
Console.WriteLine($"Error :: {args.Status.Error}");
}
});
_Replicator.Start();
// Later, stop and dispose the replicator *before* closing/disposing the database
using (var query = QueryBuilder.Select(SelectResult.All())
.From(DataSource.Database(database)))
{
// Run the query
Console.WriteLine($"Query :: {query.ToString()}");
var result = query.Execute();
Console.WriteLine($"Result :: {result.Count()}");
}
}
下面是我用于 sync_gateway 的配置 -
{
"log": ["*"],
"databases": {
"testdb": {
"server": "http://167.87.206.28:8091",
"bucket": "Test",
"username": "System",
"password": "welcome",
"enable_shared_bucket_access": true,
"import_docs": true,
"num_index_replicas": 0,
"users": {
"GUEST": { "disabled": false, "admin_channels": ["*"] }
},
"sync": `function (doc, oldDoc) {
if (doc.sdk) {
channel(doc.sdk);
}
}`
}
}
}
我正在使用命令启动 sync_gateway -
C:\Program Files\Couchbase\Sync Gateway>sync_gateway.exe ~path\sync-gateway-config.json
当我尝试运行我的控制台应用程序时,不会从服务器中提取数据并且在控制台中出现以下错误 -
不知道出了什么问题。任何线索将不胜感激!
解决方案
在 sg 配置中添加 user1:
"users": {
"user1": {"password": "pass", "admin_channels": ["*"]},
"GUEST": { "disabled": true, "admin_channels": ["*"] }
}
和
// Add authentication
replConfig.Authenticator = new BasicAuthenticator("user1", "pass");
推荐阅读
- android - Android 如何重构嵌套的 doAsync
- javascript - 建立地方流动制度的问题
- python - 熊猫根据条件选择行
- powershell - 如何使用 power shell 解析 JSON 响应?
- wso2 - WSO2 EI,Integration Studio,碳应用程序中的自定义中介
- sql - 如何从sql中删除结果查询?
- azure - 在 Azure 自动化帐户 runbook 中运行 Kubectl
- android - 如何通过 react-native 控制安卓手机的电信状态?
- python - 如何检查连接在 Python 中是否仍然存在?
- c# - UpdateSource 在 CoerceValueCallback 中不起作用