Firebase realtime database querying on a field - javascript

I have a firebase database with the following structure of employee data. I have a user table as well which has a 'companyId' property. Each time a user logs in I want to fetch all the employees which match the users 'companyId'. Is it possible to implement this using firebase database rules or I have to write some query.
Employee:
{
"+911234567890" : {
"admin" : true,
"companyId" : "C1",
"depId" : "D5",
"designation" : "D1",
"dob" : "2019-04-02T18:30:00.000Z",
"doj" : "2019-04-18T18:30:00.000Z",
"empEmail" : "nishant.k#zetwerk.com",
"empId" : "E4",
"empPhone" : "+911234567890",
"first_name" : "Nishanth",
"gender" : "male",
"last_name" : "K",
"manager" : "M2",
"type" : "permanent"
},
"+919035105184" : {
"admin" : true,
"companyId" : "C2",
"depId" : "D1",
"designation" : "Software engineer",
"dob" : "1991-07-31T18:30:00.000Z",
"doj" : "2018-07-24T18:30:00.000Z",
"empEmail" : "arpit.s#zetwerk.com",
"empId" : "E10",
"empPhone" : "+919035105184",
"first_name" : "Arpit",
"gender" : "male",
"last_name" : "Srivastava",
"manager" : "M1",
"type" : "PERMANANENT"
},
"+919698286236" : {
"admin" : false,
"companyId" : "C1",
"companyName" : "Zetwerk",
"depId" : "D1",
"depName" : "Engineering",
"empEmail" : "dhanalakshmi.s#zetwerk.com",
"empId" : "E1",
"empPhone" : "+919698286236",
"firebaseId" : "-LbNvaKFjqaaMl_JbNxd",
"first_name" : "Dhanalakshmi",
"type" : "contract"
},
"+919738749877" : {
"companyId" : "C1",
"depId" : "D2",
"empEmail" : "sagar.k#zetwerk.com",
"empId" : "E3",
"empPhone" : "+919738749877",
"firebaseId" : "-LbNbABScOEzl-sMFE1u",
"first_name" : "Sagar",
"type" : "permanent"
},
"+919972984851" : {
"admin" : true,
"companyId" : "C1",
"depId" : "D6",
"designation" : "SDE",
"dob" : "2019-04-23T18:30:00.000Z",
"doj" : "2019-04-02T18:30:00.000Z",
"empEmail" : "saikumarganji1994#gmail.com",
"empId" : "Z002",
"empPhone" : "+919972984851",
"first_name" : "Sai",
"gender" : "male",
"last_name" : "Kumar",
"type" : "permanent"
}
}
User:
"1":{
"Name" : "Nishant Gupta",
"companyId" : "C1",
"role" : "admin"
}

You indeed have to use a query, as follows. I make the assumption that you know, in your front end, the user's companyId;
var db = firebase.database();
var userCompanyId = 'C1'; //you'll probably get this value from the user profile
db.ref('Employee')
.orderByChild('companyId')
.equalTo(userCompanyId)
.once('value', function(dataSnapshot) {
dataSnapshot.forEach(function(childSnapshot) {
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
console.log('childKey : ', childKey);
console.log('childData : ', childData);
});
});
See the doc here: https://firebase.google.com/docs/database/web/lists-of-data#listen_for_value_events

Related

How to populate an array inside a document which stores uniqueID as strings and that uniqueID is from another collection rather than objectID

I have a user document as follows which holds an array of systemIDs', which is unique for another collection which holds systemID as unikey key. How to populate user with all system ID details?
User document:
{
"_id" : ObjectId("6gfg85993266db5fdgs578"),
"email" : "xyz#gmail.com",
"role" : "user",
"systemIDs" : [
"12345678",
"87654321"
],
"createdAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"updatedAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"__v" : NumberInt(0)
},
{
"_id" : ObjectId("6gfg85993266db5fdgs578"),
"email" : "abc#gmail.com",
"role" : "user",
"systemIDs" : [
"1111111",
"2135684"
],
"createdAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"updatedAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"__v" : NumberInt(0)
}
System IDs document:
{
"_id" : ObjectId("62093fdsfsdfs97e1"),
"systemID" : "12345678",
"err" : [
1, 5, 10
],
"__v" : NumberInt(0)
},
{
"_id" : ObjectId("62093fdsfsdfs97e1"),
"systemID" : "87654321",
"err" : [
3, 7
],
"__v" : NumberInt(0)
},
{
"_id" : ObjectId("62087dsfsdfs97e1"),
"systemID" : "11111111",
"err" : [
],
"__v" : NumberInt(0)
},
I want to find details of all the systemIDs a user holds which results something like this if I query my users collection with email : xyz#gmail.com, I should get the below result or populated result like shown:
{
"_id" : ObjectId("6gfg85993266db5fdgs578"),
"email" : "xyz#gmail.com",
"role" : "user",
"systemIDs" : [
{
"_id" : ObjectId("62093fdsfsdfs97e1"),
"systemID" : "12345678",
"err" : [
1, 5, 10
],
"__v" : NumberInt(0)
},
{
"_id" : ObjectId("62093fdsfsdfs97e1"),
"systemID" : "87654321",
"err" : [
3, 7
],
"__v" : NumberInt(0)
},
]
"createdAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"updatedAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"__v" : NumberInt(0)
},
I can create a foreach loop and call database each time but I suppose that wouldn't be a good practice.
I am new with this so please bear with me and explain it to me in details.
you can use aggregation with $match and $lookup to perform this task
db.users.aggregate([
{
"$match": {
"email": "xyz#gmail.com"
}
},
{
"$lookup": {
"from": "systems",
"localField": "systemIDs",
"foreignField": "systemID",
"as": "systemIDs"
}
}
])
demo

MongoDB aggregation match nested array

I´m striving to get some aggregated data from Mongo DB. I have the following collections:
I´m striving to get some aggregated data from Mongo DB. I have the following collections:
I have 2 collections:
product
{
"_id" : ObjectId("5eda578cb9c3fa1ef8c483c5"),
"brand_name" : "LAVA",
"short_description" : "Specifications",
"offer_price" : 20,
"quantity" : 5,
"variants" : [
"5eb9300438d0b83a3088feec",
"5eb92a7909823240081cd763"
],
"seller_id" : ObjectId("5e994af17a2f9b3a007e247c"),
"name" : "LAVA X10",
"createdAt" : ISODate("2020-06-05T14:32:44.582Z"),
"updatedAt" : ISODate("2020-06-05T14:32:44.582Z")
},
{
"_id" : ObjectId("5eda578cb9c3fa1ef8c483c8"),
"brand_name" : "LAVA",
"short_description" : "Specifications",
"offer_price" : 20,
"quantity" : 5,
"variants" : [
"5eb9300438d0b83a3088feed",
"5eb92a7909823240081cd763"
],
"seller_id" : ObjectId("5e994af17a2f9b3a007e247c"),
"name" : "LAVA X11",
"createdAt" : ISODate("2020-06-05T14:32:44.582Z"),
"updatedAt" : ISODate("2020-06-05T14:32:44.582Z")
}
2. attribute
{
"_id" : ObjectId("5eb92a4d09823240081cd75f"),
"is_active" : true,
"name" : "Color",
"slug" : [
{
"is_active" : true,
"_id" : ObjectId("5eb92a7909823240081cd763"),
"name" : "Green",
"updatedAt" : ISODate("2020-06-01T13:47:56.584Z"),
"createdAt" : ISODate("2020-05-11T10:35:37.357Z")
},
{
"is_active" : true,
"_id" : ObjectId("5eb92a7909823240081cd764"),
"name" : "RED",
"updatedAt" : ISODate("2020-06-01T13:47:39.236Z"),
"createdAt" : ISODate("2020-05-11T10:35:37.357Z")
}
],
"createdAt" : ISODate("2020-05-11T10:34:53.642Z"),
"updatedAt" : ISODate("2020-06-01T13:48:09.194Z"),
"__v" : 0
},
{
"_id" : ObjectId("5eb92a5409823240081cd760"),
"is_active" : true,
"name" : "Size",
"slug" : [
{
"is_active" : true,
"_id" : ObjectId("5eb92c4338d0b83a3088feeb"),
"name" : "M",
"updatedAt" : ISODate("2020-06-01T13:47:08.993Z"),
"createdAt" : ISODate("2020-05-11T10:43:15.355Z")
},
{
"is_active" : true,
"_id" : ObjectId("5eb9300438d0b83a3088feec"),
"name" : "S",
"updatedAt" : ISODate("2020-05-11T10:59:16.731Z"),
"createdAt" : ISODate("2020-05-11T10:59:16.731Z")
},
{
"is_active" : true,
"_id" : ObjectId("5eb9300438d0b83a3088feed"),
"name" : "XXL",
"updatedAt" : ISODate("2020-06-01T13:46:36.417Z"),
"createdAt" : ISODate("2020-05-11T10:59:16.731Z")
}
],
"createdAt" : ISODate("2020-05-11T10:35:00.739Z"),
"updatedAt" : ISODate("2020-06-01T13:47:08.993Z"),
"__v" : 0
}
I want to this type of result
{
"_id" : ObjectId("5eda578cb9c3fa1ef8c483c5"),
"brand_name" : "LAVA",
"short_description" : "Specifications",
"offer_price" : 20,
"quantity" : 5,
"variants" : [
"5eb9300438d0b83a3088feec",
"5eb92a7909823240081cd763"
],
"attributes" : [
{
"_id" : ObjectId("5eb92a5409823240081cd760"),
"is_active" : true,
"name" : "Size",
"slug" : {
"is_active" : true,
"_id" : ObjectId("5eb9300438d0b83a3088feec"),
"name" : "S",
"updatedAt" : ISODate("2020-05-11T10:59:16.731Z"),
"createdAt" : ISODate("2020-05-11T10:59:16.731Z")
},
"createdAt" : ISODate("2020-05-11T10:35:00.739Z"),
"updatedAt" : ISODate("2020-06-01T13:47:08.993Z"),
"__v" : 0
},
{
"_id" : ObjectId("5eb92a4d09823240081cd75f"),
"is_active" : true,
"name" : "Color",
"slug" : {
"is_active" : true,
"_id" : ObjectId("5eb92a7909823240081cd763"),
"name" : "Green",
"updatedAt" : ISODate("2020-06-01T13:47:56.584Z"),
"createdAt" : ISODate("2020-05-11T10:35:37.357Z")
},
"createdAt" : ISODate("2020-05-11T10:34:53.642Z"),
"updatedAt" : ISODate("2020-06-01T13:48:09.194Z"),
"__v" : 0
}
]
"seller_id" : ObjectId("5e994af17a2f9b3a007e247c"),
"name" : "LAVA X10",
"createdAt" : ISODate("2020-06-05T14:32:44.582Z"),
"updatedAt" : ISODate("2020-06-05T14:32:44.582Z")
},
{
"_id" : ObjectId("5eda578cb9c3fa1ef8c483c8"),
"brand_name" : "LAVA",
"short_description" : "Specifications",
"offer_price" : 20,
"quantity" : 5,
"variants" : [
"5eb9300438d0b83a3088feed",
"5eb92a7909823240081cd763"
],
"attributes" : [
{
"_id" : ObjectId("5eb92a5409823240081cd760"),
"is_active" : true,
"name" : "Size",
"slug" : {
"is_active" : true,
"_id" : ObjectId("5eb9300438d0b83a3088feed"),
"name" : "XXL",
"updatedAt" : ISODate("2020-06-01T13:46:36.417Z"),
"createdAt" : ISODate("2020-05-11T10:59:16.731Z")
},
"createdAt" : ISODate("2020-05-11T10:35:00.739Z"),
"updatedAt" : ISODate("2020-06-01T13:47:08.993Z"),
"__v" : 0
},
{
"_id" : ObjectId("5eb92a4d09823240081cd75f"),
"is_active" : true,
"name" : "Color",
"slug" : {
"is_active" : true,
"_id" : ObjectId("5eb92a7909823240081cd763"),
"name" : "Green",
"updatedAt" : ISODate("2020-06-01T13:47:56.584Z"),
"createdAt" : ISODate("2020-05-11T10:35:37.357Z")
},
"createdAt" : ISODate("2020-05-11T10:34:53.642Z"),
"updatedAt" : ISODate("2020-06-01T13:48:09.194Z"),
"__v" : 0
}
]
"seller_id" : ObjectId("5e994af17a2f9b3a007e247c"),
"name" : "LAVA X11",
"createdAt" : ISODate("2020-06-05T14:32:44.582Z"),
"updatedAt" : ISODate("2020-06-05T14:32:44.582Z")
}
// ------------ Here variants array values are attribute's slug ID -----------------
Please Help Me
Please let me know how?
That's not very effective data design: one of your collections uses ids of parts of documents in other collection. First of all you need to consider having slug._id: 1 index for attributes. Then to fetch products with included attributes which have filtered slugs use something like
db.product.find(...).map(function(prod){
prod.attributes = [];
for(sid in prod.variants){
var attr = db.attributes.find({'slug._id': sid});
attr.slug = attr.slug.find(function(slug){return slug._id == sid});
prod.atributes.push(attr);
}
return prod;
})

Filtering realtime database data

I have the following firebase database. I would like to filter and list the orders which's deliveryDuration value is "45"
"orders" : [ null, {
"comment" : "",
"date" : "2018-07-09 10:07:18",
"deliveryDuration" : "45",
"delivery_address" : "",
"item" : [ {
"available" : true,
"category" : "Dessert",
"details" : "(Hausgemacht)",
"name" : "Warmer Topfenstrudel",
"price" : 3.9,
"quantity" : 1
} ],
"orderVerified" : false,
"telefon" : "",
"userID" : "xyc#gmail.com",
"userName" : ""
}, {
"comment" : "",
"date" : "2018-07-10 10:07:33",
"deliveryDuration" : "30",
"delivery_address" : "",
"item" : [ {
"available" : true,
"category" : "Dessert",
"details" : "(Hausgemacht)",
"name" : "Warmer Topfenstrudel",
"price" : 3.9,
"quantity" : 1
} ],
"orderVerified" : false,
"telefon" : "",
"userID" : "xyc#gmail.com",
"userName" : ""
}, {
"comment" : "",
"date" : "2018-07-10 10:13:13",
"deliveryDuration" : "10",
"delivery_address" : "",
"item" : [ {
"available" : true,
"category" : "Spezialitäten",
"details" : "Schweinschnitzel mit Parmesan gebacken auf Spaghetti Napoli",
"name" : "Piccata Milanese",
"price" : 12.9,
"quantity" : 1
} ],
"orderVerified" : false,
"telefon" : "",
"userID" : "xyc#gmail.com",
"userName" : ""
}
}
I tried writing the following function:
getNewItems: function (order) {
if (db.ref('orders').child(order).child('deliveryDuration').equalTo(45)){
return db.ref('orders').child(order).child('deliveryDuration')
}}
How could I get the filtered objects? I was thinking that that i write an if-else statement and the function returns the values what i was looking for.
I think you're looking for this:
getNewItems: function (order) {
return db.ref('orders').orderByChild('deliveryDuration').equalTo(45));
}}
This Firebase query takes each child node of the location you query, orders it by the deliveryDuration property, and then filters to only get the ones who are equal to 45.

sort JSON object alphabeticly

Im trying to use underscore.js to sort my JSON object, however it doesn't seem to sort it alphabeticly when I sort by companyName?
As you can see with this code, the third object in data.adverts has doesnt start with the letter D ?
Code looks like:
var sortedDesc = _.sortBy(data.adverts, 'companyName');
$.each(sortedDesc, function () {
Doing my stuff here.....
});
The object looks like:
data({
"title" : "Krak firma API",
"query" : "http://api.eniro.com/cs/search/basic?geo_area=danmark&country=dk&search_word=DIS&version=1.1.3&callback=jQuery22003420392591506243_1456226871368",
"totalHits" : 44,
"totalCount" : 44,
"startIndex" : 1,
"itemsPerPage" : 25,
"adverts" : [{
"eniroId" : "66139761",
"companyInfo" : {
"companyName" : "Dansk Industri Service A/S",
"orgNumber" : "20250844",
"cvrPNumber" : "1004202979",
"companyText" : null
},
"address" : {
"streetName" : "Generatorvej 17",
"postCode" : "2860",
"postArea" : "Søborg",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 12.465702,
"latitude" : 55.729974
}, {
"use" : "route",
"longitude" : 12.465662,
"latitude" : 55.730202
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "70 20 70 15",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/66139761/dis",
"homepage" : "http://api.eniro.com/proxy/homepage/uANwPf5aVK2cGM31dAhxnP94Fw6wLDJmjGFCQRGYZgO51Qs6_d_2i9h4MLaWRmsw_87mP_j3IjX1e2t2Hx6_yQ==",
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dansk-industri-service-as:66139761?search_word=DIS"
}, {
"eniroId" : "66295511",
"companyInfo" : {
"companyName" : "Diss",
"orgNumber" : "30924606",
"cvrPNumber" : "1013726465",
"companyText" : null
},
"address" : {
"coName" : "Rikke Søndermølle",
"streetName" : "Hovangsvej 71",
"postCode" : "9500",
"postArea" : "Hobro",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 9.786483,
"latitude" : 56.649997
}, {
"use" : "route",
"longitude" : 9.786596,
"latitude" : 56.650012
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "58 52 62 61",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/66295511/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/diss:66295511?search_word=DIS"
}, {
"eniroId" : "66741314",
"companyInfo" : {
"companyName" : "Moster Di's Grill og Kaffevogn",
"orgNumber" : "21651605",
"cvrPNumber" : "1017404705",
"companyText" : null
},
"address" : {
"streetName" : "Hedelandsvej 14",
"postCode" : "7400",
"postArea" : "Herning",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 8.935914,
"latitude" : 56.127568
}, {
"use" : "route",
"longitude" : 8.93635,
"latitude" : 56.127463
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "97 42 04 20",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/66741314/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/moster-dis-grill-og-kaffevogn:66741314?search_word=DIS"
}, {
"eniroId" : "122768415",
"companyInfo" : {
"companyName" : "Dis Byg ApS",
"orgNumber" : "37167304",
"cvrPNumber" : "1020824162",
"companyText" : null
},
"address" : {
"streetName" : "Ved Banen 8",
"postCode" : "7100",
"postArea" : "Vejle",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 9.553109,
"latitude" : 55.698735
}, {
"use" : "route",
"longitude" : 9.553159,
"latitude" : 55.698833
}
]
},
"phoneNumbers" : [],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/122768415/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-byg-aps:122768415?search_word=DIS"
}, {
"eniroId" : "121468337",
"companyInfo" : {
"companyName" : "Dis",
"orgNumber" : null,
"cvrPNumber" : null,
"companyText" : null
},
"address" : {
"streetName" : "Studiestræde 21 A",
"postCode" : "1455",
"postArea" : "København K",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 12.5697907,
"latitude" : 55.6784752
}, {
"use" : "route",
"longitude" : 12.5697907,
"latitude" : 55.6784752
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "33 12 00 00",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/121468337/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis:121468337?search_word=DIS"
}, {
"eniroId" : "108935200",
"companyInfo" : {
"companyName" : "Seapay Dis ApS",
"orgNumber" : "36054506",
"cvrPNumber" : "1019585685",
"companyText" : null
},
"address" : {
"streetName" : "Ivar Bentsens Vej 12",
"postCode" : "4300",
"postArea" : "Holbæk",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 11.758894,
"latitude" : 55.717305
}, {
"use" : "route",
"longitude" : 11.758669,
"latitude" : 55.717311
}
]
},
"phoneNumbers" : [],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/108935200/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/seapay-dis-aps:108935200?search_word=DIS"
}, {
"eniroId" : "66303436",
"companyInfo" : {
"companyName" : "Dis-Faxe",
"orgNumber" : "33686587",
"cvrPNumber" : "1016954493",
"companyText" : null
},
"address" : {
"coName" : "Gitte Willumsen Berg",
"streetName" : "Terslev Bygade 7",
"postCode" : "4690",
"postArea" : "Haslev",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 11.969888,
"latitude" : 55.374341
}, {
"use" : "route",
"longitude" : 11.970108,
"latitude" : 55.374433
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "30 29 98 77",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/66303436/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-faxe:66303436?search_word=DIS"
}, {
"eniroId" : "68809471",
"companyInfo" : {
"companyName" : "Dis Bygge Og Ejendomsadministration",
"orgNumber" : null,
"cvrPNumber" : null,
"companyText" : null
},
"address" : {
"streetName" : "Tuborg Boulevard 12, 1. sal.",
"postCode" : "2900",
"postArea" : "Hellerup",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 12.5807377,
"latitude" : 55.7271613
}, {
"use" : "route",
"longitude" : 12.5807377,
"latitude" : 55.7271613
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "24 45 71 74",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/68809471/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-bygge-og-ejendomsadministration:68809471?search_word=DIS"
}, {
"eniroId" : "93544746",
"companyInfo" : {
"companyName" : "Dis Center ApS",
"orgNumber" : "35473009",
"cvrPNumber" : "1018749374",
"companyText" : null
},
"address" : {
"streetName" : "Hammershøj 38",
"postCode" : "9460",
"postArea" : "Brovst",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 9.596158,
"latitude" : 57.05976
}, {
"use" : "route",
"longitude" : 9.596163,
"latitude" : 57.059895
}
]
},
"phoneNumbers" : [],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/93544746/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-center-aps:93544746?search_word=DIS"
}, {
"eniroId" : "66949810",
"companyInfo" : {
"companyName" : "Dis-Danmark",
"orgNumber" : "16917338",
"cvrPNumber" : "1005846555",
"companyText" : null
},
"address" : {
"coName" : "Jan Amnitzbøl Krusell",
"streetName" : "Frøkærparken 116",
"postCode" : "8320",
"postArea" : "Mårslet",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 10.152582,
"latitude" : 56.07644
}, {
"use" : "route",
"longitude" : 10.152397,
"latitude" : 56.076574
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "24 63 62 69",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/66949810/dis",
"homepage" : "http://api.eniro.com/proxy/homepage/uANwPf5aVK26f2J7KyRZqimid0oj_3qIjQ0XbJhXGfpb4h41yM5odSv_D17GURWQlMNOi53PltI=",
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-danmark:66949810?search_word=DIS"
}, {
"eniroId" : "123661747",
"companyInfo" : {
"companyName" : "Dis Group Holding A/S",
"orgNumber" : "37226963",
"cvrPNumber" : "1020895019",
"companyText" : null
},
"address" : {
"streetName" : "Ørstedsvej 10",
"postCode" : "8660",
"postArea" : "Skanderborg",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 9.980758,
"latitude" : 56.069991
}, {
"use" : "route",
"longitude" : 9.9793,
"latitude" : 56.070543
}
]
},
"phoneNumbers" : [],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/123661747/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-group-holding-as:123661747?search_word=DIS"
}, {
"eniroId" : "109604576",
"companyInfo" : {
"companyName" : "Fonden Dis",
"orgNumber" : null,
"cvrPNumber" : null,
"companyText" : null
},
"address" : {
"streetName" : "Holmbladsgade 70 B",
"postCode" : "2300",
"postArea" : "København S",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 12.6120585,
"latitude" : 55.6648985
}, {
"use" : "route",
"longitude" : 12.6120585,
"latitude" : 55.6648985
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "32 84 11 17",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/109604576/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/fonden-dis:109604576?search_word=DIS"
}, {
"eniroId" : "66902798",
"companyInfo" : {
"companyName" : "Dis Holding ApS",
"orgNumber" : "29180407",
"cvrPNumber" : "1011836085",
"companyText" : null
},
"address" : {
"coName" : "Rikke Søndermølle",
"streetName" : "Hovangsvej 71",
"postCode" : "9500",
"postArea" : "Hobro",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 9.786483,
"latitude" : 56.649997
}, {
"use" : "route",
"longitude" : 9.786596,
"latitude" : 56.650012
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "22 99 66 96",
"label" : null
}, {
"type" : "custom",
"phoneNumber" : "40 88 83 48",
"label" : "Mobil"
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/66902798/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-holding-aps:66902798?search_word=DIS"
}, {
"eniroId" : "68536140",
"companyInfo" : {
"companyName" : "Danish Ins.for Study Abroad Dis",
"orgNumber" : null,
"cvrPNumber" : null,
"companyText" : null
},
"address" : {
"streetName" : "Ctr By ",
"postCode" : "1199",
"postArea" : "Kh K",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : null,
"latitude" : null
}, {
"use" : "route",
"longitude" : null,
"latitude" : null
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "33 11 51 91",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/68536140/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/danish-insfor-study-abroad-dis:68536140?search_word=DIS"
}, {
"eniroId" : "112589612",
"companyInfo" : {
"companyName" : "Fonden Dis",
"orgNumber" : null,
"cvrPNumber" : null,
"companyText" : null
},
"address" : {
"streetName" : "Peder Skrams Gade 23, 1. sal.",
"postCode" : "1054",
"postArea" : "København K",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 12.5895666,
"latitude" : 55.6773222
}, {
"use" : "route",
"longitude" : 12.5895666,
"latitude" : 55.6773222
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "33 15 05 30",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/112589612/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/fonden-dis:112589612?search_word=DIS"
}, {
"eniroId" : "108478586",
"companyInfo" : {
"companyName" : "Fonden Dis",
"orgNumber" : null,
"cvrPNumber" : null,
"companyText" : null
},
"address" : {
"streetName" : "Ravnsborggade 11",
"postCode" : "2200",
"postArea" : "København N",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 12.5618939,
"latitude" : 55.688666
}, {
"use" : "route",
"longitude" : 12.5618939,
"latitude" : 55.688666
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "35 36 65 05",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/108478586/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/fonden-dis:108478586?search_word=DIS"
}, {
"eniroId" : "67198842",
"companyInfo" : {
"companyName" : "Fabriksarbejder Klubben Abb Dis- Tribution",
"orgNumber" : "15624299",
"cvrPNumber" : "1005745320",
"companyText" : null
},
"address" : {
"streetName" : "Ligustervænget 9",
"postCode" : "7000",
"postArea" : "Fredericia",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 9.749819,
"latitude" : 55.610781
}, {
"use" : "route",
"longitude" : 9.749936,
"latitude" : 55.610541
}
]
},
"phoneNumbers" : [],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/67198842/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/fabriksarbejder-klubben-abb-dis-tribution:67198842?search_word=DIS"
}, {
"eniroId" : "104892983",
"companyInfo" : {
"companyName" : "Dis-Skive",
"orgNumber" : "35575154",
"cvrPNumber" : "1019219093",
"companyText" : null
},
"address" : {
"coName" : "Lone Hjorth Nielsen",
"streetName" : "Brombærvej 10",
"postCode" : "7800",
"postArea" : "Skive",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 9.027915,
"latitude" : 56.586359
}, {
"use" : "route",
"longitude" : 9.027838,
"latitude" : 56.586196
}
]
},
"phoneNumbers" : [],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/104892983/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-skive:104892983?search_word=DIS"
}, {
"eniroId" : "66957596",
"companyInfo" : {
"companyName" : "Dis Udlejning ApS",
"orgNumber" : "32143237",
"cvrPNumber" : "1015238832",
"companyText" : null
},
"address" : {
"streetName" : "Generatorvej 17",
"postCode" : "2860",
"postArea" : "Søborg",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 12.465702,
"latitude" : 55.729974
}, {
"use" : "route",
"longitude" : 12.465662,
"latitude" : 55.730202
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "70 20 70 15",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/66957596/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-udlejning-aps:66957596?search_word=DIS"
}, {
"eniroId" : "67034343",
"companyInfo" : {
"companyName" : "DI's Risk Management Forening",
"orgNumber" : "33336047",
"cvrPNumber" : "1016630620",
"companyText" : null
},
"address" : {
"coName" : "DI, 1787 v",
"streetName" : "H.C. Andersens Boulevard 18",
"postCode" : "1553",
"postArea" : "København V",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 12.568025,
"latitude" : 55.675344
}, {
"use" : "route",
"longitude" : 12.568243,
"latitude" : 55.675492
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "33 77 33 77",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/67034343/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-risk-management-forening:67034343?search_word=DIS"
}, {
"eniroId" : "66269242",
"companyInfo" : {
"companyName" : "DIs Personaleforening, DIP",
"orgNumber" : "26832039",
"cvrPNumber" : "1009390797",
"companyText" : null
},
"address" : {
"coName" : "DI, 1787 v",
"streetName" : "H.C. Andersens Boulevard 18",
"postCode" : "1553",
"postArea" : "København V",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 12.568025,
"latitude" : 55.675344
}, {
"use" : "route",
"longitude" : 12.568243,
"latitude" : 55.675492
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "40 19 80 90",
"label" : null
}, {
"type" : "custom",
"phoneNumber" : "30 59 05 02",
"label" : "Mobil"
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/66269242/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-personaleforening-dip:66269242?search_word=DIS"
}, {
"eniroId" : "66180758",
"companyInfo" : {
"companyName" : "DIS-Næstved",
"orgNumber" : "34762996",
"cvrPNumber" : "1018256270",
"companyText" : null
},
"address" : {
"coName" : "Per Hartvig-Olsen",
"streetName" : "Tornemarksvej 38",
"postCode" : "4700",
"postArea" : "Næstved",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 11.561402,
"latitude" : 55.239048
}, {
"use" : "route",
"longitude" : 11.560598,
"latitude" : 55.238628
}
]
},
"phoneNumbers" : [],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/66180758/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-næstved:66180758?search_word=DIS"
}, {
"eniroId" : "102638245",
"companyInfo" : {
"companyName" : "Dis-Sydfyn",
"orgNumber" : "35548130",
"cvrPNumber" : "1019012014",
"companyText" : null
},
"address" : {
"coName" : "Nani Krejsing",
"streetName" : "Kogtvedvej 76",
"postCode" : "5700",
"postArea" : "Svendborg",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 10.583639,
"latitude" : 55.048368
}, {
"use" : "route",
"longitude" : 10.583852,
"latitude" : 55.048192
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "65 31 60 31",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/102638245/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-sydfyn:102638245?search_word=DIS"
}, {
"eniroId" : "103192650",
"companyInfo" : {
"companyName" : "Dis-Kongeaaen",
"orgNumber" : "35585036",
"cvrPNumber" : "1019047985",
"companyText" : null
},
"address" : {
"coName" : "Jens christian Andersen",
"streetName" : "Toftager 16",
"postCode" : "6660",
"postArea" : "Lintrup",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 8.971892,
"latitude" : 55.409949
}, {
"use" : "route",
"longitude" : 8.971726,
"latitude" : 55.40997
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "74 85 54 23",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/103192650/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-kongeaaen:103192650?search_word=DIS"
}, {
"eniroId" : "67016411",
"companyInfo" : {
"companyName" : "DIS København Nord",
"orgNumber" : "31661811",
"cvrPNumber" : "1014736502",
"companyText" : null
},
"address" : {
"coName" : "Ann Christensen",
"streetName" : "Ellestien 1",
"postCode" : "2880",
"postArea" : "Bagsværd",
"postBox" : null
},
"location" : {
"coordinates" : [{
"longitude" : 12.45442,
"latitude" : 55.768364
}, {
"use" : "route",
"longitude" : 12.454607,
"latitude" : 55.768437
}
]
},
"phoneNumbers" : [{
"type" : "std",
"phoneNumber" : "22 58 86 46",
"label" : null
}
],
"companyReviews" : "http://www.dethitter.dk/brugeranmeldelse/f/67016411/dis",
"homepage" : null,
"facebook" : null,
"infoPageLink" : "http://www.krak.dk/f/dis-københavn-nord:67016411?search_word=DIS"
}
]
});
The companyName is a property inside companyInfo so you should try something like this:
var sortedDesc = _.sortBy(data.adverts, function(a){ return a.companyInfo.companyName; });
Unfortunately there is no generic "compare" function in JavaScript to return a suitable value for sort(). I'd write a compareStrings function that uses comparison operators and then use it in the sort function.
function compareStrings(a, b) {
// Assuming you want case-insensitive comparison
a = a.toLowerCase();
b = b.toLowerCase();
return (a < b) ? -1 : (a > b) ? 1 : 0;
}
places.sort(function(a, b) {
return compareStrings(a.city, b.city);
})
more detail visit here. Sorting JSON (by specific element) alphabetically

RedQueryBuilder validations

I am using the RedQueryBuilder version 0.5.0
http://0-5-0.redquerybuilder.appspot.com/ for building an Expression validator.
I want to Know, how to validate the entered expressions?
The metadata of the RedQuery Builder 0.5.0 supports css and class additions for Jquery support.
Please, suggest how to add the css metadata to the existing metadata.
The Sample MetaData is given below:
meta : {
tables : [ {
"name" : "PERSON",
"label" : "Person",
"columns" : [ {
"name" : "NAME",
"label" : "Name",
"type" : "STRING",
"size" : 10
}, {
"name" : "DOB",
"label" : "Date of birth",
"type" : "DATE"
}, {
"name" : "SEX",
"label" : "Sex",
"type" : "STRING",
"editor" : "SELECT"
}, {
"name" : "CATEGORY",
"label" : "Category",
"type" : "REF",
} ],
fks : []
} ],
types : [ {
"name" : "STRING",
"editor" : "TEXT",
"operators" : [ {
"name" : "=",
"label" : "is",
"cardinality" : "ONE"
}, {
"name" : "<>",
"label" : "is not",
"cardinality" : "ONE"
}, {
"name" : "LIKE",
"label" : "like",
"cardinality" : "ONE"
}, {
"name" : "<",
"label" : "less than",
"cardinality" : "ONE"
}, {
"name" : ">",
"label" : "greater than",
"cardinality" : "ONE"
} ]
}, {
"name" : "DATE",
"editor" : "DATE",
"operators" : [ {
"name" : "=",
"label" : "is",
"cardinality" : "ONE"
}, {
"name" : "<>",
"label" : "is not",
"cardinality" : "ONE"
}, {
"name" : "<",
"label" : "before",
"cardinality" : "ONE"
}, {
"name" : ">",
"label" : "after",
"cardinality" : "ONE"
} ]
}, {
"name" : "REF",
"editor" : "SELECT",
"operators" : [ {
"name" : "IN",
"label" : "any of",
"cardinality" : "MULTI"
}]
} ]
},

Categories

Resources