I'm creating my mobile app using phonegap.
I decided to use Couchbase to store datas; but I can't figure out if I must have to use Couchbase mobile or I can connect my app (javascript) directly with couchbase server, and how to 'query' my .net app.
I have downloaded the couchbase server on my system, but how to connect it with my app?
Can I use N1QL to 'query' the server with .NET also using phonegap? (because couchbase mobile doesn't support n1ql).
I could just call a rest web service done with .NET or maybe JAVA but so is it needed to add couchbase mobile to the app?
This is the query of C# couchbase mobile documentation:
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);
how i Call it?
This is a query in Server documentation (the previous was in mobile):
var doc = new Document<dynamic>{ Id = "document_id", Content = new {Some="value"} };
var result = bucket.Insert(doc);
Console.WriteLine(JsonConvert.SerializeObject(result.Document));
why they are different?
This is the function to connect the server to 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);
});
});
}
sorry if I'm a bit confused but I need some high level clarify to get started coding.
At a high level: you need Couchbase mobile on the device and Couchbase Server on server (cloud or on premise). To push/pull data between mobile and server you need the Couchbase Sync Gateway running (cloud or on premise). More information is available over at the Couchbase Mobile Portal for Developers.
With regards to your question as to why the .Net version of mobile and server queries are different-
The Mobile version calls into Couchbase Lite which is the embedded NoSQL database for mobile client platforms. The database is embedded in your mobile/desktop client and it syncs periodically with the Couchbase Server in the cloud via the sync gateway. So you would typically implement this in your Windows mobile app. You can also implement this in your desktop client application.
The server version - In this case, you would use the .Net SDK that queries against the Couchbase Server. You would implement this in your .Net web service app in your backend. You can implement your backend web service in any supported language including Java.
If you are considering Phonegap, you may want to refer to this tutorial. This integrates with Couchbase Lite using a swagger client- there isn't a native JS API hence the swagger based client. The Couchbase Lite syncs with the Couchbase Server via the Sync Gateway.
Related
We are currently using the Third-party HTTP Service provided by MongoDB in order to make HTTP requests to the outside world from within our app running in Atlas App Services. As per their documentation, this will be deprecated in December 2022.
However, I can't find an alternative for the future - what will be the preferred way to make HTTP requests from within Atlas App Services Apps?
I was in similar situation before as you are.
But then I realised that App Service team actually simplifies it by adding support for dependencies.
So, I can import standard axios library and starts using it seamlessly as
exports = async function(arg){
const axios = require('axios'); // is allowed here
axios.get('https://coderower.com')
.then(response => {
console.log(response.data);
})
.catch(error => {
console.log(error);
});
return {success: true}
};
I followed the official documentation and created a minor community app for my website.
What I'd like to know is if there's a way "to shim" custom data to IBM Connections Cloud when uploading my app as a JSON and then retrieve it inside the message handler after my app loads:
window.addEventListener('message', function(event) {
if (event.origin === "https://apps.collabservnext.com"){
// event.data contains the full context
console.log("Running in community named " + event.data.source.resourceId);
}
}, false);
parent.postMessage("appReady", "*");
So far I'm only getting the extraContent, source and user JSON keys in event.data. It would be awesome if there was a way to retrieve say hello: world.
Thanks.
I am trying to connect to mongodb from my express app hosted on firebase dynamic hosting. I simply created an endpoint to save a data on mongodb. This endpoint can be called from localhost(works fine) but fails to load the page on firebase deploy(Error: could not handle the request)
const chris = new User({
name: 'john',
username: `test`,
password: `${Date.now()}`
});
app.get('/user', (request, response) => {
chris.save( (err) => {
if(err) {
response.send(`error occured`);
}
response.send(`${Date.now()}`);
});
});
The issue is that there is a restriction to use network calls (Third party service calls) in the free plan.
**Answer found in Cloud Functions for Firebase - Billing account not configured**d
The restriction is about outbound access - e.g. can your Function request resources from the general internet. Its absolutely fine to use a function to respond to a webhook, or to access Google-internal services such a the Realtime Database.
If you wanted to call a third party web service (for example) you'd need to enable billing.
For the other quotas, take a look at: https://firebase.google.com/pricing/ - as you can see there are limits to the number of invocations (125,000 at time of writing) and CPU and memory (40k cpu-seconds and 40k GB-seconds) in the free tier.
I'm doing a small project where I'm using a Raspberry PI to monitor temperature and controlling a LED using Azure IOT Hub. The temperature is visualized through a dashboard portal, where you also can control the LED. I've read the documentation thoroughly but it I'm still unsure about a couple of things:
Remote Monitoring:
The Raspberry PI currently sends temperature to my IoT Hub (Device2Cloud), everything looks fine on that part. In order to display the values sent from the Raspberry PI I'm reading off the Event bus from my NodeJS backend, in the same manner as they do in this sample:
https://github.com/Azure-Samples/web-apps-node-iot-hub-data-visualization/blob/master/IoThub/iot-hub.js
Is this correct way to read device to cloud messages?
Remote Controlling
This is the part I'm very unsure about, I would like to control the LED that's connected to the Raspberry PI through Cloud2Device communication in my dashboard page. I'm not quite sure how to implement this in my Node JS backend, and I really cant find any good examples where this has been done. Any advice would be appreciated.
Regarding the remote monitoring question: yes this will work although i want to point out that the event hubs SDK for Node is still preview (and might change a bit in the future) so you should expect some quirks.
Regarding "remote controlling": in order to send cloud-to-device messages you should use the Azure IoT Hub Service SDK for Node, and here is an example of how to send a cloud to device message (copied from here)
'use strict';
var Client = require('azure-iothub').Client;
var Message = require('azure-iot-common').Message;
var connectionString = '[IoT Hub Connection String]';
var targetDevice = '[Target device that will receive the message]';
var client = Client.fromConnectionString(connectionString);
client.open(function (err) {
if (err) {
console.error('Could not connect: ' + err.message);
} else {
console.log('Client connected');
// Create a message and send it to the IoT Hub every second
var data = JSON.stringify({ text : 'foo' });
var message = new Message(data);
console.log('Sending message: ' + message.getData());
client.send(targetDevice, message, function (err) {
if (err) {
console.error('Could not send: ' + err.message);
} else {
console.log('Message sent');
}
});
}
});
You have a couple of options for remotely controlling your device. You should review this article (https://learn.microsoft.com/azure/iot-hub/iot-hub-devguide-c2d-guidance) to determine which option is most appropriate for your scenario.
You can find a cloud-to-device messages tutorial here: https://learn.microsoft.com/azure/iot-hub/iot-hub-node-node-c2d
You can find a direct methods tutorial here: https://learn.microsoft.com/azure/iot-hub/iot-hub-node-node-direct-methods
I am new in mobile development world and right now trying to understand few basic things.
I did a simple login nativescript app and from backend side did a login logic with mongoose (MongoDb) and express. But now I don't know how to proceed... How do I connect between backend and app?
Thank you in advance,
Emil
You need to expose an API from your backend, I'll assume you have done this (or can find this out - it's very well documented).
So from the client {N} you will need to access the API, calling whichever end-points you need. If you were using a JWT type approach, you should use the http module in nativescript, which might look something like this:
var http = require("http");
var result;
http.request({
url: "https://myBackend.org/api/post",
method: "POST",
headers: { "Content-Type": "application/json" },
content: JSON.stringify({ username: "ValueOne", password: "ValueTwo" })
}).then(function (response) {
result = response.content.toJSON();
console.log(result); //result.message would have the clients auth token
}, function (e) {
// console.log("Error occurred " + e);
});
You could then store the token (in persistent storage with the application-settings module) and add it to the header of any request to a different API endpoint to interact with your backend as an authenticated user.
Alternatively, you can use one of the cloud backend SDKs, e.g. Azure Mobile Services or Firebase which make your life much easier.