Ng-repeat orderBy value - json

How can I order my ng-repeat by the like_count in my json?
I have given it a bash but I am clearly missing something.
This is the repeat
item(ng-repeat="item in items | limitTo:3 | orderBy:like_count)
This is the data structure:
{
"image_url" : "bde2cca8323d098edf43389119af7748.jpg",
"title" : "This is the title",
"like_count" : "15",
"creator" : {
"profile_img" : "john-doe.jpg",
"username" : "JD",
"url" : "/John-Doe",
"first_name" : "John",
"last_name" : "Doe",
"location" : "Sydney, Australia"
}
}, {
"image_url" : "bjk23482301232234112d3232345343.jpg",
"title" : "This is the title",
"like_count" : "89",
"creator" : {
"profile_img" : "Jane-doe.jpg",
"username" : "JD",
"url" : "/Jane-Doe",
"first_name" : "Jane",
"last_name" : "Doe",
"location" : "Melbourne, Australia"
}
}

Try this..
ng-repeat="item in items | limitTo:3 | orderBy:'like_count'

Related

Create view from 2 different collections in mongoDB

I want to create a view from 2 different collections(info1, info2) in mongodb.
I need to have LoginId, FirstName,LastName,Email from info1 collection and GroupName,Type,MachName from info2 collection. Connecting field between info1 and info2 collections are "GroupName" and "Group" respectively
Below the collection content:
info1:
{
"GroupName" : "TEST Group1",
"LoginId" : "login1",
"FirstName" : "John",
"LastName" : "deo",
"Email" : "john.deo#xyz.com"
}
{
"GroupName" : "TEST Group2",
"LoginId" : "login1",
"FirstName" : "John",
"LastName" : "deo",
"Email" : "john.deo#xyz.com"
}
{
"GroupName" : "TEST Group2",
"LoginId" : "login2",
"FirstName" : "Mark",
"LastName" : "Clan",
"Email" : "mark.clan#xyz.com"
}
info2:
{
"Group" : "TEST Group1",
"Type" : "DEV",
"ActiveFlag" : "True",
"MachName" : "group1.xyz.net",
}
{
"Group" : "TEST Group2",
"Type" : "DEV",
"ActiveFlag" : "True",
"MachName" : "group2.xyz.net",
}
{
"Group" : "TEST Group1",
"Type" : "UAT",
"ActiveFlag" : "True",
"MachName" : "group1.xyz.net",
}
{
"Group" : "TEST Group2",
"Type" : "UAT",
"ActiveFlag" : "True",
"MachName" : "group2.xyz.net",
}
I want to have output as below from the view.
Expected output:
{
"GroupName" : ["TEST Group1", "TEST Group2"]
"LoginId" : "login1",
"FirstName" : "John",
"LastName" : "deo",
"Email" : "john.deo#xyz.com",
"Type" : "DEV",
"MachName" : ["group1.xyz.net","group2.xyz.net"]
},
{
"GroupName" : ["TEST Group1", "TEST Group2"],
"LoginId" : "login1",
"FirstName" : "John",
"LastName" : "deo",
"Email" : "john.deo#xyz.com",
"Type" : "UAT",
"MachName" : ["group1.xyz.net","group2.xyz.net"]
},
{
"GroupName" : ["TEST Group2"],
"LoginId" : "login2",
"FirstName" : "Mark",
"LastName" : "Clan",
"Email" : "mark.clan#xyz.com",
"Type" : "DEV",
"MachName" : ["group2.xyz.net"]
},
{
"GroupName" : ["TEST Group2"]
"LoginId" : "login2",
"FirstName" : "Mark",
"LastName" : "Clan",
"Email" : "mark.clan#xyz.com",
"Type" : "UAT",
"MachName" : ["group2.xyz.net"]
}
I have tried with below but not able to get the expected output. Can someone please help me to have view which should give the expected output from the 2 collections(info1,info2)?
Tried code(not working):
db.getCollection("info1").aggregate(
[
{
"$lookup" : {
"from" : "info2",
"localField" : "GroupName",
"foreignField" : "Group",
"as" : "g"
}
} ,
{ $match: { $and: [ {"g.ActiveFlag" : "True"} ] } },
{
"$project" : {
"LoginId" : "$LoginId",
"FirstName" : "$FirstName",
"LastName" : "$LastName",
"Email" : "$Email",
"machName" : "$g.MachName"
}
}
],
{
"allowDiskUse" : false
}
);
Demo - https://mongoplayground.net/p/SX3xH1v_2wQ
Use $group
$first
$push
Groups input documents by the specified _id expression and for each distinct grouping, outputs a document. The _id field of each output document contains the unique group by value. The output documents can also contain computed fields that hold the values of some accumulator expression.
db.info1.aggregate([
{
"$lookup": {
"from": "info2",
"localField": "GroupName",
"foreignField": "Group",
"as": "g"
}
},
{
$match: {
$and: [
{
"g.ActiveFlag": "True"
}
]
}
},
{
$group: {
_id: null, // you can goup by LoginId if you want
GroupName: { $push: "$GroupName" },
MachName: { $push: { $first: "$g.MachName" } },
LoginId: { $first: "$LoginId" },
FirstName: { $first: "$FirstName" },
Email: { $first: "$Email" },
Type: { $first: { $first: "$g.Type" } },
}
}
])
Update
Updated Demo - https://mongoplayground.net/p/0AgT3FJIB6P
Use $unwind on g after lookup pipeline
{ $unwind: "$g" }
Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.
Demo - https://mongoplayground.net/p/IGzTzEbgfl0
$group: {
_id: {
Type: "$g.Type",
LoginId: "$LoginId"
}
// ....
}

Pulling JSON data with a 3rd party library swift 4

I am using a 3rd party GitHub library in my Xcode folder. Its giving me access to Yelps API where i would like to get search results within my app. I am successfully downloading converting the data into a JSON string.
But i'm stuck on the logic of Decoding the JSON string so that i can access the actual parameters, such as name, display_address and price. I have use "Decode" before, but never through a 3rd party library. I'm sure its possible and i'm probably just a step or two steps away, but my inexperience is impeding that right now. Any help. Thank you
Here is my function to get the JSON data and below is the response i get
func getYelp() {
let yelpAPIClient = CDYelpAPIClient(apiKey: "MY_API_KEY")
yelpAPIClient.cancelAllPendingAPIRequests()
CDYelpFusionKitManager.shared.apiClient = yelpAPIClient
CDYelpFusionKitManager.shared.apiClient.searchBusinesses(byTerm: "Bars",
location: "Hollywood, California",
latitude: nil,
longitude: nil,
radius: 10000,
categories: [CDYelpBusinessCategoryFilter.bars],
locale: CDYelpLocale.english_unitedStates,
limit: 5,
offset: 0,
sortBy: CDYelpBusinessSortType.distance,
priceTiers: [CDYelpPriceTier.twoDollarSigns],
openNow: true,
openAt: nil,
attributes: nil) { (response) in
if let response = response,
let businesses = response.businesses?.toJSONString(),
businesses.count > 0 {
print(businesses)
}
}
}
Here's the data:
[
{
"name" : "The Know Where Bar",
"coordinates" : {
"latitude" : 34.101480000000002,
"longitude" : -118.3127424
},
"rating" : 4.5,
"price" : "$$",
"review_count" : 170,
"display_phone" : "(323) 871-4108",
"location" : {
"state" : "CA",
"address3" : "",
"address1" : "5634 Hollywood Blvd",
"city" : "Los Angeles",
"display_address" : [
"5634 Hollywood Blvd",
"Los Angeles, CA 90028"
],
"zip_code" : "90028",
"country" : "US"
},
"id" : "KOj4TvBuvRLXlBuG2vrZeQ",
"categories" : [
{
"title" : "Cocktail Bars",
"alias" : "cocktailbars"
},
{
"title" : "Jazz & Blues",
"alias" : "jazzandblues"
},
{
"title" : "Pubs",
"alias" : "pubs"
}
],
"transactions" : [
],
"distance" : 2232.7094070718849,
"phone" : "+13238714108",
"image_url" : "https:\/\/s3-media3.fl.yelpcdn.com\/bphoto\/Ehus0C-bAoA-6fNbwGpSYA\/o.jpg",
"is_closed" : false,
"url" : "https:\/\/www.yelp.com\/biz\/the-know-where-bar-los-angeles?adjust_creative=xVfmfDi4k3F3Jm9zaJU1CA&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=xVfmfDi4k3F3Jm9zaJU1CA"
},
{
"name" : "Lost Property Bar",
"coordinates" : {
"latitude" : 34.1019182,
"longitude" : -118.32650390000001
},
"rating" : 4.5,
"price" : "$$",
"review_count" : 143,
"display_phone" : "(323) 987-4445",
"location" : {
"state" : "CA",
"address3" : "",
"address1" : "1704 N Vine St",
"city" : "Hollywood",
"address2" : "",
"display_address" : [
"1704 N Vine St",
"Hollywood, CA 90028"
],
"zip_code" : "90028",
"country" : "US"
},
"id" : "CBYwPYYEFbpCefJ4rdiyPw",
"categories" : [
{
"title" : "Pubs",
"alias" : "pubs"
},
{
"title" : "Cocktail Bars",
"alias" : "cocktailbars"
}
],
"transactions" : [
],
"distance" : 1145.5564586880064,
"phone" : "+13239874445",
"image_url" : "https:\/\/s3-media1.fl.yelpcdn.com\/bphoto\/pswDPAX_3p73JbPEXwThag\/o.jpg",
"is_closed" : false,
"url" : "https:\/\/www.yelp.com\/biz\/lost-property-bar-hollywood?adjust_creative=xVfmfDi4k3F3Jm9zaJU1CA&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=xVfmfDi4k3F3Jm9zaJU1CA"
},
{
"name" : "Sunset & Vinyl",
"coordinates" : {
"latitude" : 34.098346200000002,
"longitude" : -118.32679779999999
},
"rating" : 4.5,
"price" : "$$",
"review_count" : 42,
"display_phone" : "(424) 646-3375",
"location" : {
"state" : "CA",
"city" : "Los Angeles",
"address1" : "1521 Vine St",
"address2" : "",
"display_address" : [
"1521 Vine St",
"Los Angeles, CA 90028"
],
"zip_code" : "90028",
"country" : "US"
},
"id" : "RKSPAI90ITxbnq1-L_F5NA",
"categories" : [
{
"title" : "Cocktail Bars",
"alias" : "cocktailbars"
},
{
"title" : "Speakeasies",
"alias" : "speakeasies"
},
{
"title" : "Lounges",
"alias" : "lounges"
}
],
"transactions" : [
],
"distance" : 916.67964443671087,
"phone" : "+14246463375",
"image_url" : "https:\/\/s3-media3.fl.yelpcdn.com\/bphoto\/w91DLpKmUGuXTF-zauYAWA\/o.jpg",
"is_closed" : false,
"url" : "https:\/\/www.yelp.com\/biz\/sunset-and-vinyl-los-angeles?adjust_creative=xVfmfDi4k3F3Jm9zaJU1CA&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=xVfmfDi4k3F3Jm9zaJU1CA"
},
{
"name" : "A Simple Bar",
"coordinates" : {
"latitude" : 34.129899999999999,
"longitude" : -118.34882
},
"rating" : 5,
"price" : "$$",
"review_count" : 168,
"display_phone" : "(323) 378-5388",
"location" : {
"state" : "CA",
"address3" : "",
"address1" : "3256 Cahuenga Blvd W",
"city" : "Los Angeles",
"display_address" : [
"3256 Cahuenga Blvd W",
"Los Angeles, CA 90068"
],
"zip_code" : "90068",
"country" : "US"
},
"id" : "qD3-5yqSyPiz-VpJtPsnkg",
"categories" : [
{
"title" : "Bars",
"alias" : "bars"
}
],
"transactions" : [
],
"distance" : 4136.336282884502,
"phone" : "+13233785388",
"image_url" : "https:\/\/s3-media2.fl.yelpcdn.com\/bphoto\/JYcRYDteiyjLh3dSAj7fCg\/o.jpg",
"is_closed" : false,
"url" : "https:\/\/www.yelp.com\/biz\/a-simple-bar-los-angeles?adjust_creative=xVfmfDi4k3F3Jm9zaJU1CA&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=xVfmfDi4k3F3Jm9zaJU1CA"
},
{
"name" : "The Woods",
"coordinates" : {
"latitude" : 34.098860000000002,
"longitude" : -118.34478
},
"rating" : 4,
"price" : "$$",
"review_count" : 456,
"display_phone" : "(323) 876-6612",
"location" : {
"state" : "CA",
"address3" : "",
"address1" : "1533 N La Brea Ave",
"city" : "Hollywood",
"address2" : "",
"display_address" : [
"1533 N La Brea Ave",
"Hollywood, CA 90028"
],
"zip_code" : "90028",
"country" : "US"
},
"id" : "UEim6Xi_sm78yDUpSfI-OQ",
"categories" : [
{
"title" : "Lounges",
"alias" : "lounges"
}
],
"transactions" : [
],
"distance" : 968.92997694605617,
"phone" : "+13238766612",
"image_url" : "https:\/\/s3-media3.fl.yelpcdn.com\/bphoto\/wUQYIlojm2d41ZL38zDMgg\/o.jpg",
"is_closed" : false,
"url" : "https:\/\/www.yelp.com\/biz\/the-woods-hollywood?adjust_creative=xVfmfDi4k3F3Jm9zaJU1CA&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=xVfmfDi4k3F3Jm9zaJU1CA"
}
]
The 3rd party library already does all the decoding for you. Don't convert the response back to a JSON string.
response.businesses is an array of CDYelpBusiness objects, which are defined like this:
public var id: String?
public var name: String?
public var imageUrl: URL?
public var isClosed: Bool?
public var url: URL?
public var price: String?
public var phone: String?
public var displayPhone: String?
public var photos: [String]?
public var hours: [CDYelpHour]?
public var rating: Double?
public var reviewCount: Int?
public var categories: [CDYelpCategory]?
public var distance: Double?
public var coordinates: CDYelpCoordinates?
public var location: CDYelpLocation?
public var transactions: [String]?
Try iterating over them and accessing their properties like this:
for business in response.businesses {
print(business.name)
}

MongoDB aggregation - group and retrieve ohters fileds

i have a collection with this documents:
{
"_id" : BinData(3,"utMu84VFQk+p6LOEE3Ia3w=="),
"DepartDate" : ISODate("2017-08-14T02:00:00.000+02:00"),
"Origin" : {
"Code" : "MIL",
"City" : "Milano",
"Country" : "IT"
},
"Destination" : {
"Code" : "TIA",
"City" : "Tirana",
"Country" : "AL"
},
"ReturnDate" : ISODate("2017-08-21T18:05:00.000+02:00"),
"SearchDate" : ISODate("2017-07-15T02:00:00.000+02:00"),
"Duration" : 150,
"Price" : "376.79",
"PriceCents" : 37679,
"Currency" : "EUR",
},
{
"_id" : BinData(3,"utMu845468+p6Lertya3w=="),
"DepartDate" : ISODate("2017-08-14T02:00:00.000+02:00"),
"Origin" : {
"Code" : "AOI",
"City" : "Ancona",
"Country" : "IT"
},
"Destination" : {
"Code" : "TIA",
"City" : "Tirana",
"Country" : "AL"
},
"ReturnDate" : ISODate("2017-08-21T18:05:00.000+02:00"),
"SearchDate" : ISODate("2017-07-15T02:00:00.000+02:00"),
"Duration" : 100,
"Price" : "376.79",
"PriceCents" : 37679,
"Currency" : "EUR",
},
.........
.........
I want to group by ONLY Destination.City and return an object with
Destination.City, Destination.Code and count. Like this example:
/* 1 */
{
"_id" : {
"Code" : "PMO",
"City" : "Palermo",
"Country" : "IT"
},
"count" : 184564.0
},
/* 2 */
{
"_id" : {
"Code" : "CAG",
"City" : "Cagliari",
"Country" : "IT"
},
"count" : 130873.0
},
......
......
I tried with this query (i use MongoBooster):
db.parsed_data.aggregate([
{ "$match" : { "Destination.Country" : "IT", "Segments" : { "$elemMatch" : { "Carrier" : "AZ" } } } },
{ "$group" : { "_id" : { "City" : "$Destination.City"}, "count" : { "$sum" : 1 } } },
{ "$project" : {"Destination.Code" : 1, "Destination.City" : 1, "Destination.Country" : 1 }},
{ "$sort" : { "count" : -1 } },
{ "$limit" : 9 }])
It returns grouped by City but it shows only the City Name.
In this way:
/* 1 */
{
"_id" : {
"City" : "Lampedusa"
}
},
/* 2 */
{
"_id" : {
"City" : "Trieste"
}
},
This is not correct.
How can i group by ONLY the Destination.City and return an object with
Destination.City, Destination.Code and count?
Thx

CRUD DATABASE Using json source

I have this .json source where the path is /my.json:
{
"Aro":[
{
"Name" : "Jhon",
"Surname" : "Kenneth",
"mobile" : 329129293,
"email" : "jhon#gmail.com"
},
{
"Name" : "Jhon",
"Surname" : "Kenneth",
"mobile" : 329129293,
"email" : "jhon#gmail.com"
},
{
"Name" : "Jhon",
"Surname" : "Kenneth",
"mobile" : 329129293,
"email" : "jhon#gmail.com"
}],
"Are":[
{
"Name" : "Thor",
"Surname" : "zvalk",
"mobile" : 349229293,
"email" : "thor#gmail.com"
},
{
"Name" : "Thor",
"Surname" : "zvalk",
"mobile" : 349229293,
"email" : "thor#gmail.com"
},
{
"Name" : "Thor",
"Surname" : "zvalk",
"mobile" : 349229293,
"email" : "thor#gmail.com"
},
]
}
I want to use it as a source in a CRUD database table in HTML.
This table is able to sporting, adding, editing, removing, updating...
You can use CRUD DataGrid with jQuery EasyUI
http://www.jeasyui.com/tutorial/app/crud2.php

How to get JSON into a Freemarker Template (FTL)

I've got a MongoDB which I query and the result I serialize and this string I send to my ftl template. Below is the serialized result:
[
{
"id" : "10",
"title" : "Test Title 1",
"partner" : {
"id" : "1",
"name" : "partner 1 ",
"location" : [{
"locationname" : "locationname 1a",
"city" : ""
},{
"locationname" : "locationname 1b",
"city" : ""
}]
}
},
{
"id" : "6",
"title" : "Test Title 2",
"partner" : {
"id" : "1",
"name" : "partner 2 ",
"location" : [{
"locationname" : "locationname 2b",
"city" : ""
}]
}
}
]
How would I use this in my ftl template?
Thanks for any help.
If you really have to serialize before giving the result to FreeMarker... The JSON syntax for maps and lists happens to be a subset of FTL, so assuming the serialized result is in res, res?eval will give you a list of maps.