Firebase database Indexing Issues - javascript

my customer database is like this:
{
"customers": {
"9115625853": {
"address": "16-37-4/3, Innespeta, Rajahmundry 533101",
"adhaar": "1111-2222-3333",
"currentPackage": {
"activation": "2016-11-22",
"dataConsumed": 5905580032,
"dataTotal": 21474836480,
"expiry": "2016-12-22",
"packageName": "5MB-20GB",
"speedDown": "5 Mbps",
"speedUp": "5 Mbps"
},
"email": "sureshk#gmail.com",
"mobileno": "9115625853",
"name": "Suresh Kumar P",
"registered": "2016-11-22"
},
"7032906292": {
"address": "46-17-24, Danavaipeta, Rajahmundry 533103",
"adhaar": "5555-2342-3633",
"currentPackage": {
"activation": "2016-11-12",
"dataConsumed": 18253611008,
"dataTotal": 21474836480,
"expiry": "2016-12-12",
"packageName": "5MB-20GB",
"speedDown": "5 Mbps",
"speedUp": "5 Mbps"
},
"email": "lakshman#laurel.solutions",
"mobileno": "7032906292",
"name": "Lakshman Rao Pilaka",
"registered": "2016-11-12"
},
"9165263347": {
"address": "722 Junius Street, Grazierville, Indiana, 7463",
"adhaar": "3935-1768-7293",
"email": "mannray#biospan.com",
"name": "Mann Ray",
"phone": 9165263347,
"registered": "2016-09-04"
}
}
}
I want an event to be fired when a child is added to the customer database where the currentPackage is not applied (ie when a customer like 9165263347 - Mann Ray) is added.
I have written code like this
firebase.database().ref('customers/')
.orderByChild('currentPackage')
.equalTo(null)
.once('child_added')
.then(function(snapshot) {
// My Code
});
I get an error
Uncaught (in promise) Error: No index defined for currentPackage(…)
My Firebase rules are as follows
{
"rules": {
".read": true,
".write": true,
"packages": {
".indexOn": "active"
},
"customers": {
".indexOn": "currentPackage"
}
}
}
I am sure, there is an error in the rule definition but somehow I am unable to get over it.
Please help.
thanks.

Related

React Native - Error reading JSON Data properly (Type Error: undefined is not an object)

currently, I'm working on a school project where we have to program an app. We need to get the latitude and Longitude from an address. I found the Google API and the HERE API, but for the Google API, you need to give credit card information so we won't use that.
I already looked around, but I couldn't find anything that could help me in my situation.
My problem is to read the data from the responseJson. I get this error.
[Tue Jan 05 2021 17:16:18.172] LOG TypeError: undefined is not an object (evaluating 'responseJson[0].ResponseView')::: Error Message
This is the code snippet that gets called
function setLocation(plz, town, street, hnr) {
fetch('https://geocoder.ls.hereapi.com/6.2/geocode.json?apiKey={API-KEY}&searchtext=' + plz + '+' + town + '+' + street + '+' + hnr, {
method: 'GET',
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson[0].ResponseView.Result.Location.DisplayPosition.Latitude);
})
.catch((error) => {
console.log(error + "::: Error Message");
});
}
This is the data that we get as a result when we call the link
{
"Response": {
"MetaInfo": {
"Timestamp": "2021-01-05T16:10:19.142+0000"
},
"View": [
{
"_type": "SearchResultsViewType",
"ViewId": 0,
"Result": [
{
"Relevance": 0.97,
"MatchLevel": "houseNumber",
"MatchQuality": {
"City": 0.89,
"Street": [
1.0
],
"HouseNumber": 1.0,
"PostalCode": 1.0
},
"MatchType": "pointAddress",
"Location": {
"LocationId": "NT_G0ZsvdP1AfF4LQmxtYsKjC_xUD",
"LocationType": "point",
"DisplayPosition": {
"Latitude": 50.11163,
"Longitude": 8.66109
},
"NavigationPosition": [
{
"Latitude": 50.11168,
"Longitude": 8.66128
}
],
"MapView": {
"TopLeft": {
"Latitude": 50.1127542,
"Longitude": 8.6593371
},
"BottomRight": {
"Latitude": 50.1105058,
"Longitude": 8.6628429
}
},
"Address": {
"Label": "Savignystraße 15, 60325 Frankfurt am Main, Deutschland",
"Country": "DEU",
"State": "Hessen",
"County": "Frankfurt am Main",
"City": "Frankfurt am Main",
"District": "Westend",
"Street": "Savignystraße",
"HouseNumber": "15",
"PostalCode": "60325",
"AdditionalData": [
{
"value": "Deutschland",
"key": "CountryName"
},
{
"value": "Hessen",
"key": "StateName"
},
{
"value": "Frankfurt am Main",
"key": "CountyName"
}
]
}
}
}
]
}
]
}
}
I don't know if data in response is an array or object. I'm considering that its an object as you pasted as response.
It should be like
res.Response.View[0].Result[0].Location.DisplayPosition.Latitude
res.Response.View[0].Result[0].Location.DisplayPosition.Longitude

How to parse json response in javascript?

After making a call to rest api I am getting this data in javascript.
{
"error": false,
"orders": [
{
"oid": "764",
"cid": "423",
"name": "Akshay jain",
"address": "infront of gwal magra talab",
"mobile": "11111111",
"email": "abcd#gmail.co",
"odate": "2016-03-28 21:50:45",
"status": "NEW ORDER",
"payment": "1",
"ddate": "2016-03-28",
"dtime": "1"
},
{
"oid": "763",
"cid": "438",
"name": "Vishwakarma Ji",
"address": "Narayan Pura Road",
"mobile": "0000000000",
"email": null,
"odate": "2016-03-28 20:02:06",
"status": "Confirmed (Ready for Delivery)",
"payment": "1",
"ddate": "2016-03-28",
"dtime": null
}
]
}
This is how i am storing in controller.
$scope.result = Order.query(); // where Order is a service in angularjs
If i am trying to print $scope.result.error it is giving object object not the actual error value.
How to parse error and orders in javascript and save it in a variable?
If this Order.Query is async, you have to set the result in a callback
app.controller("OrderIndexCtrl",function($scope,Order) {
Order.query(function(data){
if(data.error == false) {
$scope.result = data.orders;
}
else {
...
}
});
});
Try using the following code.
$scope.result = JSON.parse(Order.query());
Source: this question

Unable to get entire information from linkedIn api

I have tried this
Html:
<a id="li_ui_li_gen_1432549871566_0-link" class="" href="javascript:void(0);" onclick="onLinkedInLoad();" style="margin-bottom: 20px;">
JS code:
function onLinkedInLoad(logintype) {
IN.User.authorize(function(){
callback();
});
}
function callback(){
IN.Event.on(IN, "auth", OnLinkedInAuth);
OnLinkedInAuth();
}
function OnLinkedInAuth(){
IN.API.Profile("me")
.fields("firstName", "lastName", "industry", "location:(name)", "picture-url", "headline", "summary", "num-connections", "public-profile-url", "distance", "positions", "email-address", "educations:(id,school-name,field-of-study,start-date,end-date,degree,activities,notes)","languages:(id,language:(name),proficiency:(level,name))","skills:(id,skill:(name))", "date-of-birth")
.result(ShowProfileData)
.error(displayProfilesErrors);
}
function ShowProfileData(profiles) {
console.log(profiles); return false;
//its gives me json responce
/* {
"_total": 1,
"values": [{
"_key": "~",
"distance": 0,
"emailAddress": "xxxxx#gmail.com",
"firstName": "xxxx",
"headline": "xxxxx",
"industry": "Information Technology and Services",
"lastName": "xxx",
"location": {"name": "xxx Area, India"},
"numConnections": 117,
"positions": {
"_total": 1,
"values": [{
"company": {
"id": xxxxx,
"industry": "E-Learning",
"name": "xxxx",
"size": "501-1000 employees",
"type": "Privately Held"
},
"id": 485779823,
"isCurrent": true,
"startDate": {
"month": 2,
"year": 2013
},
"title": "xxxxx"
}]
},
"publicProfileUrl": "https://www.linkedin.com/pub/xxxxx/xx/xx/xx"
}]
} */
}
function displayProfilesErrors(error) {
profilesDiv = document.getElementById("profiles");
profilesDiv.innerHTML = error.message;
console.log(error);
}
It looks to me that some queried fields (e.g. languages, skills, education fields) require that your application have been approved for the Apply with LinkedIn program.
See: Profile field descriptions page which lists fields that require an additional API (i.e. 'Member profile fields available to Apply with LinkedIn developers' title), and see how one can apply for using this API: Request access to this API page.

PouchDb - remove object inside document

I'm an Italian PouchDb and AngularJS Developer.
My json document is:
{
"_id": "6",
"_rev": "3-f7283d7683cd6fb15753f494aad1d49f",
"name": "Ivrea",
"owners": [
{
"owner_id": 1,
"name": "asdas",
"address": "asdas",
"gender": "Uomo",
"type": "Assente",
"notes": [
]
},
{
"owner_id": 2,
"name": "balbaba",
"address": "blabla",
"gender": "Uomo",
"type": "Assente",
"notes": [
]
}
]
}
and after an ng-click action, I will delete owner_id: 2 object inside _id: 6 document. In API reference I found only document delete action, but not how to delete object inside document.
Thanks for your reply!!
Alessandro
You just need to put() the main document back in the database after you remove an object from it. :)
db.get('foo').then(function (doc) {
delete doc.whatever;
return db.put(doc);
}).catch(function (err) { /* ... */ });

Request a complete response object instead of compact reponse object foursquare venues search api?

When we request a api call to foursquare for search venues of certain category
It returns a compact response not complete response because of which i am not able to get complete information about the place like if the place is open, price etc which is only returned in a complete response, can i get a complete response instead of compact response?? more info provided here.
Eg:
call:https://api.foursquare.com/v2/venues/search?ll=18.5308225,73.8474647&categoryId=4bf58dd8d48988d1e1931735&radius=1000&v=20131021&limit=1
Result:
{
"meta": {
"code": 200
},
"response": {
"venues": [{
"id": "4b975471f964a520c9ff34e3",
"name": "Yana Sizzler & Wok",
"contact": {
"phone": "+912066013897",
"formattedPhone": "+91 20 6601 3897"
},
"location": {
"address": "F C Road",
"lat": 18.52802688063791,
"lng": 73.84272476029567,
"distance": 589,
"cc": "IN",
"city": "Pune",
"state": "India",
"country": "India"
},
"categories": [{
"id": "4bf58dd8d48988d1df931735",
"name": "BBQ Joint",
"pluralName": "BBQ Joints",
"shortName": "BBQ",
"icon": {
"prefix": "https:\/\/ss1.4sqi.net\/img\/categories_v2\/food\/bbq_",
"suffix": ".png"
},
"primary": true
}],
"verified": false,
"restricted": true,
"stats": {
"checkinsCount": 542,
"usersCount": 402,
"tipCount": 19
},
"specials": {
"count": 0,
"items": []
},
"hereNow": {
"count": 0,
"groups": []
},
"referralId": "v-1386276988"
}]
}
}
But i am not getting informatiion like isOpen Price etc which we get in the complete response when we use explore.
The API does not support returning complete objects in venue search responses—you need to make a separate venue details call to get the information you're looking for. We recommend caching venue details (for up to 30 days) to avoid having to repeatedly calling this endpoint to retrieve this information that doesn't necessarily change that often.

Categories