我正在使用phonegap创建我的移动应用。
我决定使用Couchbase来存储数据;但我无法弄清楚我是否必须使用Couchbase mobile或者我可以直接将我的应用程序(javascript)与couchbase服务器连接,以及如何查询'我的.net app。
我已经在我的系统上下载了couchbase服务器,但是如何将它与我的应用程序连接?
我可以使用N1QL来查询' .NET的服务器也使用phonegap? (因为couchbase mobile不支持n1ql)。
我可以用.NET或者JAVA来调用休息网络服务,但是需要将couchbase mobile添加到应用程序中吗?
这是C#couchbase移动文档的查询:
var document = database.CreateDocument();
var properties = new Dictionary<string, object>()
{
{"type", "list"},
{"title", "title"},
{"created_at", DateTime.UtcNow.ToString ("o")},
{"owner", "profile:" + userId},
{"members", new List<string>()}
};
var rev = document.PutProperties(properties);
Debug.Assert(rev != null);
我怎么称呼它?
这是服务器文档中的查询(之前是移动版):
var doc = new Document<dynamic>{ Id = "document_id", Content = new {Some="value"} };
var result = bucket.Insert(doc);
Console.WriteLine(JsonConvert.SerializeObject(result.Document));
为什么他们不同?
这是将服务器连接到phonegap的功能:
var DB_NAME = 'todo';
function initRESTClient(url) {
var client = new SwaggerClient({
spec: window.spec,
usePromise: true,
})
.then(function (client) {
client.setHost(url);
if (device.platform == 'android') {
var encodedCredentials = "Basic " + window.btoa(url.split('/')[1].split('@')[0]);
client.clientAuthorizations.add("auth", new SwaggerClient.ApiKeyAuthorization('Authorization', encodedCredentials, 'header'));
}
client.server.get_all_dbs()
.then(function (res) {
var dbs = res.obj;
if (dbs.indexOf(DB_NAME) == -1) {
return client.database.put_db({db: DB_NAME});
}
return client.database.get_db({db: DB_NAME});
})
.then(function (res) {
return client.document.post({db: DB_NAME, body: {title: 'Couchbase Mobile', sdk: 'PhoneGap'}});
})
.then(function (res) {
console.log('Document ID :: ' + res.obj.id);
})
.catch(function (err) {
console.log(err);
});
});
}
抱歉,如果我有点困惑,但我需要一些高级别的澄清才能开始编码。
答案 0 :(得分:0)
在较高级别:您需要设备上的Couchbase mobile和服务器上的Couchbase Server(云端或内部部署)。要在移动设备和服务器之间推送/拉取数据,您需要运行Couchbase Sync Gateway(云端或内部部署)。有关更多信息,请访问Couchbase Mobile Portal for Developers。
答案 1 :(得分:0)
关于.Net版本的移动和服务器查询为何不同的问题 -
Mobile版本调用Couchbase Lite,这是用于移动客户端平台的嵌入式NoSQL数据库。数据库嵌入在您的移动/桌面客户端中,并通过同步网关定期与云中的Couchbase服务器同步。因此,您通常会在Windows移动应用中实现此功能。您也可以在桌面客户端应用程序中实现此功能。
服务器版本 - 在这种情况下,您将使用针对Couchbase服务器查询的.Net SDK。您可以在后端的.Net Web服务应用程序中实现此功能。您可以使用任何支持的语言(包括Java)实现后端Web服务。
如果您正在考虑使用Phonegap,您可能需要参考此tutorial。这与使用swagger客户端的Couchbase Lite集成 - 没有本机JS API因此基于swagger的客户端。 Couchbase Lite通过Sync Gateway与Couchbase服务器同步。