Strongloop not able use mongodb function - angularjs

I'm using AngularJS Sdk from Strongloop to develop the mobile application with ionicframework.
In between the development progress, i failed to use the mongodb function from angular. I always get the unexpected result without any error message. Hope can get some help. Thanks.
var feed$ = Feed.find({
filter : {
$or : [{ accountId : "569a9fc898e6f58b0329eefc" }, { accountId : "569a9fa098e6f58b0329eefb" }]
}
});

Loopback AngularJS SDK provides client-side representation of the models and remote methods in the LoopBack server application. What you actually use is not MongoDB query (at least not directly). You are calling angular service which is calling remote method from persisted model on server. Loopback then translates your request to query using database connector. In your case this is MongoDB connector.
That being said correct way to use find method in loopback angularjs sdk is:
Feed.find({
filter: {
where: {
or: [{accountId: "569a9fc898e6f58b0329eefc"}, {accountId: "569a9fa098e6f58b0329eefb"}]
}
}
},
function (feeds) {
console.log(feeds); //query result is available in callback function
});

Related

breeze odata and normal web api

I need to have two entityManagers in an angular app using breese so that I can get data from two different services. One service is an OData API and the other is a standard breeze web api (asp.net web api using breeze controllers).
My OData context works fine but when I create the standard one the uriBuilder property is still odata and when this manager trys to get metedata is is prefixing the $metadata value onto the end of the url.
breeze.config.initializeAdapterInstance('modelLibrary', 'backingStore', true);
breeze.NamingConvention.camelCase.setAsDefault();
var serviceName = common.testApiUrl;
var metadataStore = createMetadataStore();
does anyone know if its even possible to have the two setup?
I have managed to get this working and the trick is to use the DataService to contruct the entitymanagers. This means that they're separate objects with their own configuration and you can indeed use OData and WebApi together.
Here is how I did it:
Create a data service object
var dataService = new breeze.DataService({
serviceName: myConfig.testApiUrl,
hasServerMetadata: true,
adapterName: 'WebApi'
});
Instantiate an entity manager using this data service
function newManager() {
var mgr = new breeze.EntityManager({
dataService: dataService
});
return mgr;
}
You can then use this same pattern for however many you need and just change the adapter name. There is some extra config but all standard breeze stuff so I haven't included it all here.
I then create a DataContext for each EntityManager to encapsulate them and I can then just inject the context that I need as and when I need it.

Get client ip address in Angularjs / ionic framework

I have a php vote system where I check the voting table for the user ip address before inserting new votes into the vote table...
My question is how do I get the client ip address in my input form using angularjs.
I am building a mobile app with IONIC framework for android.
Thanks in advance.
You can try like this
var json = 'http://ipv4.myexternalip.com/json';
$http.get(json).then(function(result) {
console.log(result.data.ip)
}, function(e) {
alert("error");
});
Or
If you don't wanna to use external service, you can use this cordova plugin [ working example]
Like this
networkinterface.getIPAddress(function (ip) {
alert(ip);
});

PhoneGap AngularJS Strongloop MongoDB Firebase

I'm trying to setup an alternative to Firebase with loopback API REST(with mongodb connector) in NodeJS, when I implement it with the $http ressource to my PhoneGap apps in AngularJS,
it is not update in realtime like Firebase.
My factory is like:
function syncUsers(){
return $http.get(userUrl).then(function(res){
return res.data;
});
in my controllers:
UserSrv.syncUsers().then(function(res)
{ $scope.data.users = res});
my question is : why my apps don't update the old data, and why I need to refresh the apps to have the new data ?
Thank you.
Ok even if I don't know how to implement it, I need to use pub/sub
Strong loop work on it.
https://github.com/strongloop/strong-pubsub/issues/7

How can I mock the results of the GMail API?

We are using the GMail API and developing an application on top of it. Ideally I would like to have some golden emails to test the analytics engine against. This way I can develop the analytics engine without having to worry about fetching the emails and hence without a network connection. What is the best way to achieve this? I noticed that App Engine (which we use) now allows you to mock DataStore/memcache etc. and run nosetests, but I don't know how to do this across local appserver restarts.
The Mock class provided by googleapis/google-api-python-client looks like a good candidate for your use case.
from googleapiclient.discovery import build
from googleapiclient.http import HttpMock
mock = HttpMock('mock-email-list.json', {'status': '200'})
gmail = build('gmail', 'v1', http=mock)
response = gmail.users().messages().list(userId='me').execute()
print(response)
Where mock-email-list.json content is of the form
{
"messages":[
{
"id":"abcd",
"threadId":"abcd"
},
{
"id":"efgh",
"threadId":"abcd"
},
],
"resultSizeEstimate":2
}
As a side note, after your test has run, you can also check what url the mock has been used for (by the gmail client):
assert mock.uri == 'https://gmail.googleapis.com/gmail/v1/users/me/messages?alt=json'
The Gmail API nor the client libraries provide special functionality for mocking email fetching. You'll need to build out the mocks on your own.

Azure mobile services backend "mssql" object not found

I am trying to create a custom API for Azure Mobile Services that does a Transact-SQL command on the table. According to the docs I should be able to use an object called 'mssql' to do this (http://msdn.microsoft.com/en-us/library/jj554212.aspx). However, the object does not seem to exist and my backend script always fails with error 500 (internal server error). Does this object not exist in custom API backend scripts?
To use that object in a custom API, you should access it via the request object passed to the API:
exports.get = function(request, response) {
var mssql = request.services.mssql;
mssql.query('select GETDATE() from myTable', {
success: function(results) {
response.send(200, { serverTime: results[0] });
}
});
}

Resources