How can authentication details be stored json-ld compliant way? - json

This may be a dumb question, but I am architecting a web app from scratch and looking for content to be stored in MongoDB in a JSON-LD compliant way.
My user Schema looks something like this:
{"auth": {
"local": {
"email": String,
"password": String,
},
"firebase" : {
"uid" : String
},
"facebook": {
"id" : String,
"token" : String,
"email" : String,
"name" : String
}
},
"profile_contents" : {
"id" : {
"firstname" : {"value": String},
"lastname" : {"value": String},
"email" : [String],
"dob": Date,
"gender": {type: String, enum: genderTypes}
},
"profile" : {
"displayName": String,
"img": String,
"website" : String,
"organisation": String
}
}}
Questions:
Most of the content in the id and profile objects will make its way to a restful endpoint. It makes sense for these to be mapped to schemas. But the Auth object will rarely (never?) be exposed to the API and will be used for backend operations.. should these still be mapped to a schema, if so, how?
Regardless of the answer to (1) are there scehmas suited to mapping credentials like those listed? (e.g. suppose we want to expose auth.firebase.uid at one point.. should this be part of a custom vocab or mapped to an already existing one? Schema.org didn't have anything (other than accountId - which seems to be aimed at eCommerce payment use cases).
Thanks!

Related

How to upload array of strings in mysql

I want to insert array of string in my product table, i am very new in this mysql. like in mongodb i do it like this to store list of photos
const productSchema = mongoose.Schema({
name : {type:String,trim : true},
preview : String,
photos : [String],
description : String,
isAccessory : Boolean,
brand : String,
price : Number
})
and this is my request body
{
"id": "1",
"name": "Men Navy Blue Solid Sweatshirt",
"preview": "https://assets.myntassets.com/h_1440,q_100,w_1080/v1/assets/images/7579188/2018/11/5/08a7b230-ee8f-46c0-a945-4e835a3c01c01541402833619-United-Colors-of-Benetton-Men-Sweatshirts-1271541402833444-1.jpg",
"photos": [
"https://assets.myntassets.com/h_1440,q_100,w_1080/v1/assets/images/7579188/2018/11/5/08a7b230-ee8f-46c0-a945-4e835a3c01c01541402833619-United-Colors-of-Benetton-Men-Sweatshirts-1271541402833444-1.jpg",
"https://assets.myntassets.com/h_1440,q_100,w_1080/v1/assets/images/7579188/2018/11/5/efc3d5b9-1bb3-4427-af53-7acae7af98951541402833591-United-Colors-of-Benetton-Men-Sweatshirts-1271541402833444-2.jpg",
"https://assets.myntassets.com/h_1440,q_100,w_1080/v1/assets/images/7579188/2018/11/5/c7e58861-3431-4189-9903-9880f5eebd181541402833566-United-Colors-of-Benetton-Men-Sweatshirts-1271541402833444-3.jpg",
"https://assets.myntassets.com/h_1440,q_100,w_1080/v1/assets/images/7579188/2018/11/5/66490b64-32de-44b4-a6e4-fe36f1c040051541402833548-United-Colors-of-Benetton-Men-Sweatshirts-1271541402833444-4.jpg",
"https://assets.myntassets.com/h_1440,q_100,w_1080/v1/assets/images/7579188/2018/11/5/957be784-7c5d-4e90-ab9f-0928015b22891541402833645-United-Colors-of-Benetton-Men-Sweatshirts-1271541402833444-5.jpg"
],
"description": "Navy solid sweatshirt with patchwork, has a round neck, long sleeves, straight hem",
"isAccessory": false,
"brand": "United Colors of Benetton",
"price": 2599
},
now how can i do this in sql like what the table design for it.
As per my understanding I can think of two possible options:
Option-1:
MySQL supports storing JSON. Store the string array in as a value against the desired key.
Option-2:
Store the string value with JSON.stringify.

How to add variables in json file?

Below is json file. I want to use variables for db password and db username. How can I add a variable in json ?
{
"name" : "mydb3",
"storage" : {
"binaryStorage" : {
"type" : "database",
"driverClass" : "com.mysql.jdbc.Driver",
"url" : "$jdbcdburl",
"username" : "$jdbcusername",
"password" : "$jdbcpassword"
}
},
"workspaces" : {
"default" : "default",
"allowCreation" : true
}
}
You can either build the JSON up using something like JSON Variables
https://www.npmjs.com/package/json-variables
Or you can load the JSON into memory look for the key and update it, example below using Node.JS
How to update a value in a json file and save it through node.js
Either way you wouldn't have to store the username and passwords in clear text, which is what I am guessing your are trying to avoid?
You may want to try Jsonnet, a data templating language, that is an extension of JSON and can export JSON files. E.g.
{
person1: {
username: "Alice",
password: "abc",
welcome: "Hello " + self.username + "!",
},
person2: self.person1 { username: "Bob", password: "123" },
}
would produce
{
"person1": {
"password": "abc",
"username": "Alice",
"welcome": "Hello Alice!"
},
"person2": {
"password": "123",
"username": "Bob",
"welcome": "Hello Bob!"
}
}
Other than fields you can also declare variables using local, e.g.
local pi = 3.14;
You can use string interpolation + backslash...
See "{{testUrl}}" in Postman exported JSON for exmaple:
Variable value:
"info":{
"_postman_id": "YOUR-ID-IN-POSTMAN",
"name": "YOU-EXPORTED-COLLECTION-FILE-NAME",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"testUrl": "https://www.techeader.com"},
Variable implemented in raw:
"url":{
"raw": "\"{{testUrl}}\"",
"protocol": "http",
"host": ["test","com"]},
JSON is a standard format for representing objects as a textual, human readable (most of the time :-/ ) format. The concept of a variable is not applicable in this context. Variables exist in memory/code only, and a variable can be written to JSON format in a file for example, but with the risk of sounding "blunt" IMHO, your question doesn't make much sense at this point.
If you elaborate a little more on what you want to achieve in your application, I might be able to help you better.

How to use full text search with arango REST API as I'm always getting empty result?

Data in Arango:
{
"employees": [
{
"lastName": "Ansari",
"firstName": "Haseb"
},
{
"lastName": "Ansari",
"firstName": "Affan"
},
{
"lastName": "Keshav",
"firstName": "Anil"
}
],
"_id": "test/124518952473",
"_rev": "124518952473",
"_key": "124518952473"
}
Indexing:
POST http://localhost:8529/_db/db_test/_api/index?collection=test
Body:
{
"type" : "fulltext",
"fields" : [
"lastName"
]
}
Searching:
PUT http://localhost:8529/_db/db_test/_api/simple/fulltext
Body:
{
"collection" : "test",
"attribute" : "lastName",
"query" : "Ansari"
}
I want in my application to use REST API for full text search. Please help me where I am going wrong here. And this is one document in arango store just for example. Otherwise, i'll be having more documents hence full-text search.
Short: Your index is not on a field in your document.
Long:
You're saving one document, it has a list employees, but no document lastname - thats inside of employees but this won't match the path.
You can however make it work if you put the fulltext index on employees, then all attributes of the object employees will be indexed. You then however will match on first and last name.
If you want to do this separate, you need to directly match a token like that:
employees[0].lastName

Migrating from MySQL to Couchbase Server (NoSQL)

I am planning to move some of my RDBMS tables to a NoSQL environment. I have different modules and associated tables as shown below.
1. General
News table
Trainings table
Knowledge table
2. Application_x
Clicks table
Crashes table
Note : This is a sample scenario
In this case, this is how i defined Nosql (Couchbase server) structure. Please correct me if this is wrong.
The purpose of migration is mainly intended for searching.
{
"General":[
"news" : [{
"id" : "123",
"title" : "test title"
},
{
"id" : "345",
"title" : "test title 2"
}],
"trainings" :[{
"id" : "1",
"name" : "training 1"
},
{
"id" : "2",
"name" : "training 2"
}],
"knowledge" :[{
"id" : "1",
"categ" : "programming"
},
{
"id" : "2",
"categ" : "management"
}]
],
"Application_x": [
"clicks" : [{
"userid" : "1",
"area" : "1850",
},
{
"userid" : "2",
"area" : "258",
}],
"crashes" :[{
"userid" : "1",
"severity" : "1",
},
{
"userid" : "2",
"severity" : "8",
}]
]
}
Can someone correct me if my approach is not correct ?
Thanks in advance,
Tismon Varghese.
By reading your question, I am left scratching my head as to what your approach is. In a NoSQL database (such as couchbase) - you don't have the idea of tables and columns. Each object is serialized to JSON and stored in plain text. Yes, this creates duplication, but the drawbacks of duplication are greatly outweighed by the benefits of scalability.
In this example, using Couchbase, you would probably want to create one Couchbase bucket per application. That way, should you need to migrate to a different Couchbase cluster at a later date, a minimal amount of configuration is required. Each row in your tables gets created as a separate object in Couchbase. There is no need to separate the object types within the bucket.
This blog entry contains some detailed instructions on how to migrate from mySQL to Couchbase.
On a side note, I might recommend using Couchbase combined with Elasticsearch.

Displaying MySQL data as JSON in ASP.NET, Restful web service?

I Followed This to Read MySQL DataBase and Display Tables in ASP.net.
But I want to Display Those Tables as the Part of JSON data,
For Example :
This is Employ Table,
And I wnat to Display this Data in the form of JSON
Like :
[
{
"id" : 1,
"first_name" : "John",
"last_name" : "Doe"
},
{
"id" : 2,
"first_name" : "Bob",
"last_name" : "Smith"
},
{
"id" : 3,
"first_name" : "Jane",
"last_name" : "Doe"
}
]
Here I want to Use the MySQL Tables as JSON Using ASP.net/Restfulweb services,So that it can be used in the part of Android and iPhone.
Any Suggestion please,
Take a look at this example
How-to-create-a-JSON-WCF-RESTful-Service