I'm building a app that is going to serve as an agenda or a scheduling book for some services. It's planned to the app to work in a "per customer" way, Angular in the front-end and to use the new Google Firestore, for all the real time and pseudo-backendless stuff.
The question is, as I have never worked with NoSQL databases before, how should I structure the data inside Firestore?
I thought about something that would look like this:
{
//Collection
"customer-a": {
//Document
"info": {
"name": "Customer A",
"Phones": [{
"contact-name": "",
"number": ""
}],
"address": {
"type": "street",
"name": "",
"number": 0,
"neighborhood": "",
"city": "",
"state": "",
"zipcode": "",
"country": "",
"coordinates": {
"latitude": "",
"longitude": ""
}
}
},
//Document
"config": {
"active-theme": "",
"themes": [{}]
},
//Document
"customer-data": {
//SubCollection
"employees": {
//Document
"employee-a": {
"name": "",
"phone": "",
"rattings": [],
"address": {
"type": "street",
"name": "",
"number": 0,
"neighborhood": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
},
//SubCollection
"schedulings": {
//Document
"2017": {
"total": 300,
"scheduling": [{
"client": {
"name": "",
"phone": "",
"rating": 5,
},
"price": 10,
"services": [{
"name": "",
"price": 10
}],
"datetime": "",
}]
},
"2018": {
"total": 300,
"scheduling": [{
"client": {
"name": "",
"phone": "",
"classificacao": 5,
},
"price": 10,
"services": [{
"name": "",
"price": 10
}],
"datetime": "",
}]
},
}
}
},
//SubCollection
"stock": {}
}
}
}
I'm thinking on splitting the scheduling into years because I think it may grow in size a lot, but as I said, I've never worked with this kind of database, so I don't really know how much data I could nest inside a document, for example...
As an exaggerated amount of data for a base calculation I thought about around 200k "objects" that would be stored for each employee per year, is that much or it's ok to store that much data nested?
Should I keep creating sub collections inside Firestore or it should be one single collections to store only different documents and nest everything?
Hope someone can help me,
Thanks.
Related
I have a JSON API response that contains multiple entries, with different types of subscriptions and multiple users.
I need to search the list for a "user_name" AND a "subscription", then return any matching "duration". In some cases, there will be more than one "duration" for a user and subscription. I would need the total (sum) of the duration when there is more than one.
For example, here is a part of an example Json I am working with:
[
{
"id": 139387026,
"user_name": "John Smith",
"note": "",
"last_modify": "2022-03-28 14:16:35",
"date": "2022-03-28",
"locked": "0",
"addons_external_id": "",
"description": "",
"info": [
{
"subscription": "basic",
"duration": "22016",
}
]
},
{
"id": 139387027,
"user_name": "John Smith",
"note": "",
"last_modify": "2022-03-28 14:16:35",
"date": "2022-03-28",
"locked": "0",
"addons_external_id": "",
"description": "",
"info": [
{
"subscription": "advanced",
"duration": "10537",
}
]
},
{
"id": 139387028,
"user_name": "Martin Lock",
"note": "",
"last_modify": "2022-03-28 14:16:35",
"date": "2022-03-28",
"locked": "0",
"addons_external_id": "",
"description": "",
"info": [
{
"subscription": "basic",
"duration": "908",
}
]
},
]
So for example, for user_name: "John Smith" and subscription: "advanced", I need to return duration: "10537".
I've used toJsonlist(); to convert it, then used the code below, but it returns all values in the list. I can't figure out how to search for the specific values or add matching entries together.
rows = subscriptions.toJsonlist();
for each row in rows
{
info row;
user_name = row.getJson("user_name");
info "username: " + user_name;
subscription = row.getJson("subscription");
info "subscription: " + subscription;
subscriptionId = row.getJson("subscriptionId");
info "subscription Id: " + subscriptionId;
}
I'm fairly new to programming. Any help is appreciated!
According to your needs , you want to filter your JSON data and get the corresponding value from your filter in user_name and subcription.
Here is the Deluge Script for that. I use clear variable name so that it will not confused you.
//Your Entry Change this based on your filter
input_user_name = "John Smith";
input_subscription = "advanced";
//Your JSON data
json_string_data = '[ { "id": 139387026, "user_name": "John Smith", "note": "", "last_modify": "2022-03-28 14:16:35", "date": "2022-03-28", "locked": "0", "addons_external_id": "", "description": "", "info": [ { "subscription": "basic", "duration": "22016", } ] }, { "id": 139387027, "user_name": "John Smith", "note": "", "last_modify": "2022-03-28 14:16:35", "date": "2022-03-28", "locked": "0", "addons_external_id": "", "description": "", "info": [ { "subscription": "advanced", "duration": "10537", } ] }, { "id": 139387028, "user_name": "Martin Lock", "note": "", "last_modify": "2022-03-28 14:16:35", "date": "2022-03-28", "locked": "0", "addons_external_id": "", "description": "", "info": [ { "subscription": "basic", "duration": "908", } ] } ]';
//Declare the data as JSON
processed_json_data = json_string_data.toJsonlist();
initial_total_duration = 0;//Donot change this
list_of_duration = List();
total_duration_per_username_per_subscription = Map();
for each row in processed_json_data
{
if (row.get("user_name") == input_user_name )
{
info_list = row.get("info").toJSONList();
for each info_row in info_list
{
if (info_row.get("subscription") == input_subscription)
{
info_row_duration = info_row.get("duration").toLong(); // make it integer
list_of_duration.add(info_row_duration);
}
}
}
}
result_map = Map();
//Sum of list_of_duration
for each duration in list_of_duration
{
initial_total_duration = initial_total_duration + duration;
}
result_map.put("user_name",input_user_name);
result_map.put("subscription",input_subscription);
result_map.put("no_of_subscription",list_of_duration.size());
result_map.put("total_duration",initial_total_duration);
info result_map;
And the result should be
{"user_name":"John Smith","subscription":"advanced","no_of_subscription":1,"total_duration":10537}
You can test these script in https://deluge.zoho.com/tryout.
Thanks,
Von
i want to fetch results according to columns stored in metadata column...where json data is stored as string
criteria:- fetch price from metadata from column name stored in type. type can have fixedPrice,timedAuction, unlimitedAuction
i am using npm module- mysql#2.18.1
phpmyadmin - Server version: 8.0.27-0ubuntu0.20.04.1 - (Ubuntu)
I want to implement this in sql query itself
meta data after parsing:-
"metadata": {
"file": "https://ipfs.io/ipfs/QmctyySWTJtLGDjCQkDd7N9DjhpY9ffvmPZ8JiYm1Y9t1a",
"putOnMarketplace": true,
"fixedPrice": {
"price": 0.1,
"currency": "",
"name": "Tester colectibles 2",
"description": "scs",
"royalties": "10",
"multipleCopies": "",
"invitationCode": "959671"
},
"timedAuction": {
"price": "",
"expirationDate": {
"id": 1,
"value": "1 Day"
},
"name": "",
"description": "",
"royalties": "",
"invitationCode": ""
},
"unlimitedAuction": {
"price": "",
"name": "",
"description": "",
"royalties": "",
"invitationCode": ""
},
"mediaType": "image",
"type": "fixedPrice",
"tokenType": "erc721"
}
I need to import some JSON data am getting into my database. I'd like to use PowerShell and figured out a little, but I need help getting the final piece together.
How to convert following nested JSON to flat CSV in Powershell?
Following is the JSON data :
$openings = '{"objects": [
{
"id": 136691,
"title": "UX Desginer",
"description": "Hiring a UX Designer for our Front End Team",
"position_type": "full_time",
"is_remote_allowed": false,
"is_archived": false,
"is_private": false,
"state": "Draft",
"location": {
"city": "Bangalore",
"state": "Karnataka",
"zipcode": "560078",
"country": "India"
},
"team": "Front-end Team",
"created_date": 1472804002,
"modified_date": 1472804018,
"application_email": "recruiterbox-dmcc0616#applications.recruiterbox.com",
"hosted_url": "https://recruiterbox.recruiterbox.com/jobs/d933h5yh"
},
{
"id": 136691,
"title": "UX Desginer",
"description": "Hiring a UX Designer for our Front End Team",
"position_type": "full_time",
"is_remote_allowed": false,
"is_archived": false,
"is_private": false,
"state": "Draft",
"location": {
"city": "Bangalore",
"state": "Karnataka",
"zipcode": "560078",
"country": "India"
},
"team": "Front-end Team",
"created_date": 1472804002,
"modified_date": 1472804018,
"application_email": "recruiterbox-dmcc0616#applications.recruiterbox.com",
"hosted_url": "https://recruiterbox.recruiterbox.com/jobs/d933h5yh"
}
],
"meta": {
"total": 1,
"limit": 20,
"offset": 0
}}'
I am using QuickBooks Online Plus, which means i can edit the item. I would like to use the API to change the on hand # for an item. I've created an item "test1" through QuickBooks Online Plus. When i read the item from API i got the following in the attached json file. things looks great as follow:
{
"QueryResponse": {
"Item": [
{
"Name": "test1",
"Active": true,
"FullyQualifiedName": "test1",
"Taxable": false,
"UnitPrice": 3,
"Type": "Inventory",
"IncomeAccountRef": {
"value": "60",
"name": "Sales of Product Income"
},
"PurchaseCost": 1,
"ExpenseAccountRef": {
"value": "61",
"name": "Cost of Goods Sold"
},
"AssetAccountRef": {
"value": "62",
"name": "Inventory Asset"
},
"TrackQtyOnHand": true,
"QtyOnHand": 6,
"InvStartDate": "2015-12-02",
"domain": "QBO",
"sparse": false,
"Id": "19",
"SyncToken": "1",
"MetaData": {
"CreateTime": "2015-12-01T14:38:23-08:00",
"LastUpdatedTime": "2015-12-01T14:38:42-08:00"
}
}
],
"startPosition": 1,
"maxResults": 1
},
"time": "2015-12-02T09:59:29.936-08:00"
}
But when i tried to update that item using the json object below:
{
"Name": "test1",
"Active": true,
"Taxable": false,
"UnitPrice": 3,
"Type": "Inventory",
"IncomeAccountRef": {
"value": "60",
"name": "Sales of Product Income"
},
"PurchaseCost": 1,
"ExpenseAccountRef": {
"value": "61",
"name": "Cost of Goods Sold"
},
"AssetAccountRef": {
"value": "62",
"name": "Inventory Asset"
},
"TrackQtyOnHand": true,
"QtyOnHand": 16,
"InvStartDate": "2015-12-02",
"domain": "QBO",
"sparse": false,
"Id": "19",
"SyncToken": "2"
}
, i got an error like this:
{"Fault":{"Error":[{"Message":"Stale Object Error","Detail":"Stale Object Error : You and seven.li#hotschedules.com were working on this at the same time. seven.li#hotschedules.com finished before you did, so your work was not saved.","code":"5010","element":""}],"type":"ValidationFault"},"time":"2015-12-02T10:42:52.466-08:00"}
I would like to update the on hand quantity. Does anyone know what's wrong and how to do it? Thanks.
The problem is with the "SyncToken". I believe when you try to update the new item, you should not increment the "SyncToken", you should keep it the same. QBO will update the "SyncToken" for you.
This question already has an answer here:
Using underscore to sort nested objects in an array
(1 answer)
Closed 7 years ago.
I have a complex JSON array: a typical array element is the following:
{
"runner": {
"_id": "5625ebf3d0ca02d7092d46e3",
"title": "pid",
"url": "runner",
"user": {
"_id": "5w24e437wb35c31w4fc47wf2",
"avatar": {
"src": "cew52ee16r037fc89625946621226597c7922ac.jpg"
}
},
"start_date": "2015-11-11T19:30:00.000Z",
"end_date": "2015-11-11T21:30:00.000Z",
"privacy": {
"scope": "public"
},
"tqx_payment": {
"invoice_data": {
"tax_name": "",
"tax_rate": 0,
"vat_number": "",
"address": "",
"city": "",
"state": "",
"country": "",
"company": ""
},
"currency": "USD"
},
"published": true,
"deleted": false,
"timezone": "Europe/Rome"
},
"_id": "56264096a1ae9d316635b9b5",
"type": "default"
}
I want to sort all the elements in the array by runner.start_date. Is this possible? How?
[SOLVED] by trial and error this way:
_.sortBy(JSONArray, function(itm) {
return [itm.runner.start_date];
});