How to use structured data (JSON-LD) for a local business that is made up of several sub businesses - json-ld

I built a website for a local business that has a golf course, indoor sports complex (tennis, racquetball, wally ball, batting cages, nautilus), a restaurant, does catering, and offers weddings and receptions. Not sure how to get started. Any help is appreciated.

Good Afternoon,
The following example might be helpful. Please note, for #id I've made the assumption that you've created a dedicated page for each entity and indicated that link in the example but it doesn't have to be a working link therefore if you haven't created a dedicated page you can create a unique id for each entity (this id should not change over time). Please see definitions of department and subOrganization at schema.
<script type="application/ld+json">
{
"#context" : "http://schema.org",
"#type" : "LocalBusiness",
"name" : "Business Name",
"#id" : "http://www.your-company-site.com",
"logo" : "http://www.your-company-site.com/logo.jpg",
"sameAs" : [ "", "" ],
"url" : "http://www.your-company-site.com",
"email" : "example#your-company-site.com",
"faxNumber" : "+1-401-555-1213",
"contactPoint" : {
"#type" : "ContactPoint",
"telephone" : "+1-401-555-1212",
"contactType" : "customer service"
},
"openingHoursSpecification": [
{
"#type": "OpeningHoursSpecification",
"dayOfWeek": [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ],
"opens": "09:00",
"closes": "21:00"
},
{
"#type": "OpeningHoursSpecification",
"dayOfWeek": [ "Saturday", "Sunday" ],
"opens": "10:00",
"closes": "23:00"
}
],
"department" : [
{
"#type" : "GolfCourse",
"name" : "Golf Course Name",
"#id" : "http://www.your-company-site.com/golf-course-dedicated-page-url",
"logo" : "http://www.your-company-site.com/logo.jpg",
"sameAs" : [ "", "" ],
"url" : "http://www.your-company-site.com/golf-course-dedicated-page-url",
"email" : "golfcourse#your-company-site.com",
"faxNumber" : "+1-401-555-1215",
"contactPoint" : {
"#type" : "ContactPoint",
"telephone" : "+1-401-555-1214",
"contactType" : "customer service"
},
"openingHoursSpecification": [
{
"#type": "OpeningHoursSpecification",
"dayOfWeek": [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ],
"opens": "09:00",
"closes": "19:00"
},
{
"#type": "OpeningHoursSpecification",
"dayOfWeek": [ "Saturday", "Sunday" ],
"opens": "09:00",
"closes": "17:00"
}
]
},
{
"#type" : "TennisComplex",
"name" : "Tennis Complex Name",
"#id" : "http://www.your-company-site.com/tennis-complex-dedicated-page-url",
"logo" : "http://www.your-company-site.com/logo.jpg",
"sameAs" : [ "", "" ],
"url" : "http://www.your-company-site.com/tennis-complex-dedicated-page-url",
"email" : "tenniscomplex#your-company-site.com",
"faxNumber" : "+1-401-555-1216",
"contactPoint" : {
"#type" : "ContactPoint",
"telephone" : "+1-401-555-1215",
"contactType" : "customer service"
},
"openingHoursSpecification": [
{
"#type": "OpeningHoursSpecification",
"dayOfWeek": [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ],
"opens": "09:00",
"closes": "19:00"
},
{
"#type": "OpeningHoursSpecification",
"dayOfWeek": [ "Saturday", "Sunday" ],
"opens": "09:00",
"closes": "17:00"
}
]
}
],
"subOrganization" : {
"#type" : "Restaurant",
"name" : "Restaurant Name",
"#id" : "http://www.your-company-site.com/restaurant-dedicated-page-url",
"logo" : "http://www.your-company-site.com/logo.jpg",
"sameAs" : [ "", "" ],
"url" : "http://www.your-company-site.com/restaurant-dedicated-page-url",
"email" : "restaurant#your-company-site.com",
"faxNumber" : "+1-401-555-1217",
"contactPoint" : {
"#type" : "ContactPoint",
"telephone" : "+1-401-555-1216",
"contactType" : "customer service"
},
"openingHoursSpecification": [
{
"#type": "OpeningHoursSpecification",
"dayOfWeek": [ "Monday", "Tuesday" ],
"opens": "11:30",
"closes": "22:00"
},
{
"#type": "OpeningHoursSpecification",
"dayOfWeek": [ "Wednesday", "Thursday", "Friday" ],
"opens": "11:30",
"closes": "23:00"
},
{
"#type": "OpeningHoursSpecification",
"dayOfWeek": [ "Saturday", "Sunday" ],
"opens": "16:00",
"closes": "23:00"
}
]
}
}
</script>

Related

How to replace the value in nested arrays in multiple mongodb docs at once

Here i wanted to replace the value of country to something else wherever it presents like "India".
I have multiple docs with same structure and would like update all at once. It should not affect other keys and just wanted to update the country.
Tried with Set operator and not getting it correctly.
{
"_id" : "1",
"teams" :
[
{
"type" : "local",
"isEnabled" : "true",
"Country":"India"
"names" :
[
{ "name": "kumar","Nationality":"indian","BirthPlace":"Goa","Age":"U25" },
{ "name": "kannan","Nationality":"indian","BirthPlace":"Kerala","Age":"U25"}
]
},
{
"type" : "national",
"isEnabled" : "true",
"Country":"India"
"names" :
[
{ "name": "kumar","Nationality":"indian","BirthPlace":"Goa","Age":"U25" },
{ "name": "kannan","Nationality":"indian","BirthPlace":"Kerala","Age":"U25"}
]
},
{
"type" : "international",
"isEnabled" : "true",
"Country":"England"
"names" :
[
{ "name": "kumar","Nationality":"indian","BirthPlace":"Goa","Age":"U25" },
{ "name": "kannan","Nationality":"indian","BirthPlace":"Kerala","Age":"U25"}
]
},
{
"type" : "national",
"isEnabled" : "true",
"Country":"India"
"names" :
[
{ "name": "kumar","Nationality":"indian","BirthPlace":"Goa","Age":"U25" },
{ "name": "kannan","Nationality":"indian","BirthPlace":"Kerala","Age":"U25"}
]
},
{
"type" : "international",
"isEnabled" : "true",
"Country":"Newzealand"
"names" :
[
{ "name": "kumar","Nationality":"indian","BirthPlace":"Goa","Age":"U25" },
{ "name": "kannan","Nationality":"indian","BirthPlace":"Kerala","Age":"U25"}
]
}
]
}
Try this one:
db.collection.updateMany(
{},
{ $set: { "teams.$[element].Country": "Republic of India" } },
{ arrayFilters: [{ "element.Country": "India" }] }
);
Try this one:
db.collection.updateMany({},
{
$set: {
"teams.$[].Country": "India"
}
})

Deleting Object from Nested Array MongoDB

I am trying to delete the object with the id: "2019-08-22T04:53:11.357Z" from this users portfolio array.
I have searched for the correct query filter to help me delete the object but nothing seems to be working!
Here is the data we are working with. There is currently only one user
(InStock) in the system but more will be added in the future.
[
{
"id": "MTg4MDU3ODM2MDk2NDU0NjU3",
"name": "InStock",
"balance": 7760,
"portfolio": [
{
"id": "2019-08-22T04:15:22.998Z",
"name": "Jordan Shoe",
"size": "10.5",
"price": 150
},
{
"id": "2019-08-22T04:36:37.836Z",
"name": "Nike Tee",
"size": "M",
"price": 35
},
{
"id": "2019-08-22T04:53:11.357Z",
"name": "Adidas Shoe",
"size": "8.5",
"price": 100
}
],
"history": [
]
}
]
and here is what I was trying using what I've seen in other solutions.
db.collection(collectionName).updateOne({"id": "MTg4MDU3ODM2MDk2NDU0NjU3"}, {$pull : {"portfolio": {"id": "2019-08-22T04:36:37.836Z"}}})
I am looking for the line to remove the Adidas Shoe object from InStock's portfolio array.
Try this query:
db.test1.updateOne({"_id" : ObjectId("5d5e7a291b761bfc0420e580")},
{$pull: {"portfolio": {"name": "Adidas Shoe"}}} )
After execution:
{
"_id" : ObjectId("5d5e7a291b761bfc0420e580"),
"portfolio" : [
{
"id" : "2019-08-22T04:15:22.998Z",
"name" : "Jordan Shoe",
"size" : "10.5",
"price" : 150.0
},
{
"id" : "2019-08-22T04:36:37.836Z",
"name" : "Nike Tee",
"size" : "M",
"price" : 35.0
}
],
"name" : "InStock",
"balance" : 7760.0
}
It's Working Fine for you.
db.collection(collectionName).updateOne({"id": "MTg4MDU3ODM2MDk2NDU0NjU3"},
{ $pull: { portfolio: { $elemMatch: { id:"2019-08-22T04:36:37.836Z"} }},

why mongodb aggregate return empty array if not match on filter

This is my sample collection. i want to filter by fees, getting value with matched query. if query doesnot match it return with null.
[{
"college_id" : 25,
"name" : "IIT",
"city" : "Delhi",
"courses" : [
{
"discipline_name" : "engineering",
"course_list" : [
{
"course_type" : "Bachelor of Technology [B.Tech]",
"program_name_list" : [
{
"program_name" : "Bachelor of Technology [B.Tech] (Biotechnology)",
"fees" : 60000,
},
{
"program_name" : "Bachelor of Technology [B.Tech] (Electrical Engineering)",
"fees" : 40000,
}
]
},
{
"course_type" : "Master of Technology [M.Tech]",
"program_name_list" : [
{
"program_name" : "Master of Technology [M.Tech] (Biotechnology)",
"fees" : 40000,
},
{
"program_name" : "Master of Technology [M.Tech] (Electrical Engineering)",
"fees" : 20000,
}
]
}
]
}
]
}]
Output should be
[{
"college_id" : 25,
"name" : "IIT",
"city" : "Delhi",
"courses" : [
{
"discipline_name" : "engineering",
"course_list" : [
{
"course_type" : "Master of Technology [M.Tech]",
"program_name_list" : [
{
"program_name" : "Master of Technology [M.Tech] (Biotechnology)",
"fees" : 40000,
},
{
"program_name" : "Master of Technology [M.Tech] (Electrical Engineering)",
"fees" : 20000,
}
]
}
]
}
]
}]
I have tried below query with $match but getting the same output.
my query is
[
{
"$project": {
"name": 1,
"city": 1,
"courses": {
"$map": {
"input": {
"$filter": {
"input": "$courses",
"as": "l1",
"cond": {
"$eq": [
"$$l1.discipline_name",
"engineering"
]
}
}
},
"as": "l2",
"in": {
"discipline_name": "$$l2.discipline_name",
"course_list": {
"$map": {
"input": {
"$filter": {
"input": "$$l2.course_list",
"as": "l3",
"cond": [
// for course type filter
]
}
},
"as": "l4",
"in": {
"course_type": "$$l4.course_type",
"program_name_list": {
"$map": {
"input": {
"$filter": {
"input": "$$l4.program_name_list",
"as": "l5",
"cond": {
"$or": [
{
"$and": [
{
"$gt": [
"$$l5.fees",
0
]
},
{
"$lt": [
"$$l5.fees",
200000
]
}
]
}
]
}
}
},
"as": "l6",
"in": {
"program_name": "$$l6.program_name",
"fees": "$$l6.fees",
}
}
}
}
}
}
}
}
}
}
}]
Output of this query is
[{
"name" : "IIT",
"city" : "Delhi",
"courses" : [
{
"discipline_name" : "engineering",
"course_list" : [
{
"course_type" : "Bachelor of Technology [B.Tech]",
"program_name_list" : [
// getting this null
]
},
{
"course_type" : "Master of Technology [M.Tech]",
"program_name_list" : [
{
"program_name" : "Master of Technology [M.Tech] (Biotechnology)",
"fees" : 40000,
},
{
"program_name" : "Master of Technology [M.Tech] (Electrical Engineering)",
"fees" : 20000,
}
]
}
]
}
]
}]
I have tried $match after the $project but it doesn't work. i also tried
$match: {$ne: ["courses.course_list.program_name_list", [] ]}. it returns null.

How can I get only unique objects from JSON with the following conditions in angularjs

How can I get only unique objects from JSON with the following conditions:
processed == true
selected.type === 'Intercompany' || payee.selected.type === 'Intercompany - OT'
I don’t want to write a separate JavaScript function. Trying to achieve that in HTML.
My HTML So far:
<div data-ng-repeat="payee in data.contacts | filter: {processed:true }">
<blink data-ng-if="payee.selected.type === 'Intercompany' || payee.selected.type === 'Intercompany - OT'"><span class="pinkVouchers">PAID Vouchers - {{payee.selected.title}} - {{payee.selected.type}}</span></blink>
</div>
My JSON:
[
{
"hidden": true,
"processed": true,
"selected": {
"title": "Test Assessor 2",
"userId": "1082495",
"name": "Test Assessor 2",
"province": "Ontario",
"custId": "133300",
"groupId": "",
"regNo": "Yes",
"type": "Intercompany"
}
},
{
"hidden": true,
"processed": true,
"selected": {
"title": "Test Atkins",
"userId": "1155027",
"name": "Test Atkins",
"province": "British Columbia",
"custId": "1234",
"groupId": "",
"regNo": "No",
"type": "Intercompany"
}
},
{
"hidden": true,
"processed": true,
"selected": {
"title": "Test Assessor 2",
"userId": "1082495",
"name": "Test Assessor 2",
"province": "Ontario",
"custId": "133300",
"groupId": "",
"regNo": "Yes",
"type": "Intercompany"
}
},
{
"hidden": false,
"processed": false,
"selected": {
"title": "Test Assessor",
"userId": "1082466",
"name": "Test Assessor",
"province": "Ontario",
"custId": "1111",
"groupId": "",
"regNo": "No",
"type": "Intercompany - OT"
}
}
]
I was thinking the only way possible was with the AngularJS Filter. But I have found the difference between the version I was using and yours: the need to call the filter attributes like objects. Try this on ngRepeat:
var module = angular.module("myModule", []);
module.controller("myController", function($scope) {
$scope.message = "Test";
$scope.myArray = [ {
"hidden" : true,
"processed" : true,
"selected" : {
"title" : "Test Assessor 2",
"userId" : "1082495",
"name" : "Test Assessor 2",
"province" : "Ontario",
"custId" : "133300",
"groupId" : "",
"regNo" : "Yes",
"type" : "Intercompany"
}
}, {
"hidden" : true,
"processed" : true,
"selected" : {
"title" : "Test Atkins",
"userId" : "1155027",
"name" : "Test Atkins",
"province" : "British Columbia",
"custId" : "1234",
"groupId" : "",
"regNo" : "No",
"type" : "Intercompany"
}
}, {
"hidden" : true,
"processed" : true,
"selected" : {
"title" : "Test Assessor 2",
"userId" : "1082495",
"name" : "Test Assessor 2",
"province" : "Ontario",
"custId" : "133300",
"groupId" : "",
"regNo" : "Yes",
"type" : "Intercompany"
}
}, {
"hidden" : false,
"processed" : false,
"selected" : {
"title" : "Test Assessor",
"userId" : "1082466",
"name" : "Test Assessor",
"province" : "Ontario",
"custId" : "1111",
"groupId" : "",
"regNo" : "No",
"type" : "Intercompany - OT"
}
} ];
/*$scope.myArray = $scope.myArray.filter(function( obj ) {
return obj.processed && (obj.selected.type === 'Intercompany' || obj.selected.type === 'Intercompany - OT');
});*/
});
module.filter('unique', function () {
return function (collection) {
var newCollection = [];
angular.forEach(collection, function (item) {
var isDuplicate = false;
for (var i = 0; i < collection.indexOf(item); i++) {
if (angular.equals(item, newCollection[i])) {
isDuplicate = true;
break;
}
}
if (!isDuplicate) {
newCollection.push(item);
}
});
return newCollection;
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<div ng-app="myModule">
<div ng-controller="myController">
<div ng-repeat="payee in myArray | filter : ({selected:{type: 'Intercompany'}} || {selected:{type:'Intercompany - OT'}}) && {processed:true} | unique">
{{payee.selected.userId}}
</div>
</div>
</div>

Sort ng-repeat grouping by boolean value

In my angular js attempt, I have a json :
[
{
"id": "1111",
"peopleRelated": [
{
"summary": "Manager",
"personName": "Suzanne",
"personId": 382043,
"rated" : true
},
{
"summary": "VP",
"personName": "Dave",
"personId": 34532
"rated" : false
}
],
"title": "Title1",
},
{
"id": "2222",
"peopleRelated": [
{
"summary": "Manager",
"personName": "Kevin",
"personId": 38864
"rated" : true
}
],
"title": "Title2",
}
]
And html is following :
<div ng-repeat="mydata in data>
<div ng-repeat="personData in mydata.peopleRelated">
{{personData.personName}}
<div>
</div>
I wish to sort the personName such as "rated=false" names appear first.
How should I go for this?
Thanks
Not quite sure if this is what you're asking but
<div ng-repeat="personData in mydata.peopleRelated | orderBy:'rated'">
{{personData.personName}} {{personData.rated}}
<div>
sorts the inner loop

Resources