I have a strapi project and A flights has somr relations like drones, pilots. For example if we using postman to get a flight i send :
{
"data" : {
"Duration" : "10",
"Address" : "Address",
"account": 1,
"drone": "1",
"pilot": 1,
"User": 1,
"zone": 1,
}
}
the response is :
{
"id": 25,
"Duration" : "10",
"Address" : "Address",
"account": 1,
"drone": "1",
"pilot": 1,
"User": {
"id": 1,
"username": "AhmedMedhat",
"email": "ahmedmedhat1231#gmail.com",
"provider": "local",
"password": "$2a$10$8tkwcp73AbE0aylQyOsIdefgSiuaoOcPJzbZWxk9W2IN85SghOIjO",
"resetPasswordToken": null,
"confirmationToken": null,
"confirmed": false,
"blocked": false,
"createdAt": "2022-11-03T06:32:57.225Z",
"updatedAt": "2022-11-03T06:35:05.902Z"
},
"zone": 1,
}
only the user is populated successfully but the other relations always return null ..
maybe bec user is plugin and others is api i don't know, it works in the strapi built in routes but my customized one doesn't work .. can anyone help ??
Related
I am new to mongodD. Although i have wrote correct logic to push object inside cardsData bankCardsArray, but i am not able to make logic to edit a card.
**I have following Data in MongoDB, **
UserData = {
"_id": "63b43ab32fc8d3c100cafecc",
"name": "Praveen Lohar",
"email": "pr********#gmail.com",
"password": "$2b$12$3nwifHakrBu94BwLXAC4Nu16Kw0.xyW8vAIPTMSgY7cYttVklDIZq",
"loginIdsArray": [
{
"title": "Airtel App",
"logoIndex": 3,
"category": "Finance",
"app": "Airtel Thanks",
"username": "p******#gmail.com ",
"password": "xxxxxxx",
"isFavourite": false,
"_id":"63b440ee738a50fc333df3ca"
}
],
"cardsData": {
"bankCardsArray": [
{
"title": "SBI CC",
"logoIndex": 72,
"category": "Bank",
"cardHolder": "Prsscscs",
"cardNumber": "524xxxxxxxx20xx",
"expiry": "23/54",
"cvv": "00",
"isFavourite": false,
"_id": "63b974adb9acaa24a4ebec8b"
},
{
"title": "AXIS CC",
"logoIndex": 85,
"category": "Bank",
"cardHolder": "blsllslss",
"cardNumber": "524xxxxxxxx20xx",
"expiry": "23/54",
"cvv": "00",
"isFavourite": false,
"_id": "63b974adb9acaa24a4ebe5f"
}
],
"identityCardsArray": [
{
"title": "Aadhar Card",
"logoIndex": 98,
"category": "Identity",
"cardHolder": "Name_1",
"cardNumber": "54*******455454",
"issueDate": "2012",
"dob": "23/05",
"isFavourite": false,
"_id":"63b974e6bd0d03c116955f67"
}
],
"licenseCardsArray": [
{
"title": "Two Wheeler License",
"logoIndex": 0,
"category": "License",
"cardHolder": "Klaus Michealson",
"licenseNumber": "RJ/22/ADL-542/474/01",
"expiry": "2036",
"dob": "13/06",
"isFavourite": false,
"_id":"63b97535bd0d03c116955f69"
}
]
}
}
I want to find the user with _id
Then for that user i want to got to cardsData object
Then in cardsData object i want to got to bankCardsArray
Then in bankCardsArray , i want to update fields of a card with particular id
Const res = findOneAndUpdate(
{ 'cardsData.bankCardsArray._id':card_id },
{ $set{ 'cardsData.bankCardsArray.$.title': req.body.title });
Use "." operator to access nested fields.
Refer these mongodb documentation
query-array-of-documents
query-embedded-documents.
Hope this helps.
I have a strapi project and A single users have relation a single profile. For example if we using postman to get a single user it have response
[
{
"id": 45,
"username": "test",
"email": "test#gmail.com",
"provider": "local",
"confirmed": true,
"blocked": false,
"createdAt": "2022-07-18T08:50:43.642Z",
"updatedAt": "2022-07-18T08:50:43.642Z",
"profile": null
}
]
As you can see a user have a profile but have a null value. So when I tried to post a profile in strapi api http://localhost:1337/api/profiles?populate=* with body of json like this
{
"data" : {
"name": "fgh",
"address": "jksdjkdjs",
"phone": "345345",
"email" : "test#gmail.com" /// I tried to add this but the response is 500 internal server error
}}
It worked and status 200 ok but it didn't get the relation of the email from user
{
"data": {
"id": 12,
"attributes": {
"name": "fghdff",
"address": "jksdjkdjs",
"phone": 34534235,
"createdAt": "2022-08-05T13:48:29.548Z",
"updatedAt": "2022-08-05T13:48:29.548Z",
"publishedAt": "2022-08-05T13:48:29.547Z",
"email": {
"data": null
}
}
},
"meta": {}}
Any Idea how to post a relation in strapi? I tried to read docs or strapi forum but no one counter this problem
For someone facing how to POST relation in strapi we can use the ID of the User. For example to post and connect in my question is
{
"data" : {
"name": "dayee",
"address": "jksdjkdjs",
"phone": "34534235",
"email" : 77 // Post relation using ID
}}
I'm trying to 'unwind' columns from an included table of a query, but i'm not getting it right, I've tried the following solution:
Remove 'included' Table Name from response - Sequelize
Unsucessfully
So far I'm able to create the following query:
include: {
model: Branches,
as: 'userBranches',
include: {
model: Countries,
as: 'branchCountry',
attributes: ['countryName'],
},
},
}),
Getting the following:
"data": [
{
"id": "758406e2-47ce-4f1e-b4be-492103ee2f91",
"whatsappNumber": "5531975080415",
"whatsappId": "5531975080415",
"businessName": "Quintal da Dirce",
"cnpj": "123456789",
"email": "lepcbelisario#gmail.com",
"ownerFirstName": "Leandro",
"ownerMiddleName": "Parisi",
"ownerLastName": "Carvalho",
"ownerCpf": "123456789",
"password": "123456789",
"botName": "Walle",
"logo": null,
"isActive": true,
"createdAt": "2021-06-26T21:52:03.330Z",
"updatedAt": "2021-06-26T21:52:03.330Z",
"userBranches": [
{
"id": "f7488e1d-5fc4-4314-b7bd-f500e6b77c3f",
"userId": "758406e2-47ce-4f1e-b4be-492103ee2f91",
"managerName": "Leandro",
"branchName": "Quintal da Dirce 2000",
"countryId": 1,
"stateId": 1,
"cityId": 1,
"neibourhood": "Minha Kombi",
"street": "rua da kombui",
"streetNumber": "222",
"streetComplement": "222",
"postalCode": "12345",
"isActive": true,
"createdAt": "2021-06-26T21:52:03.347Z",
"updatedAt": "2021-06-26T21:52:03.347Z",
"branchCountry": {
"countryName": "Brazil"
}
},
But i would like to get:
"data": [
{
"id": "758406e2-47ce-4f1e-b4be-492103ee2f91",
"whatsappNumber": "5531975080415",
"whatsappId": "5531975080415",
"businessName": "Quintal da Dirce",
"cnpj": "123456789",
"email": "lepcbelisario#gmail.com",
"ownerFirstName": "Leandro",
"ownerMiddleName": "Parisi",
"ownerLastName": "Carvalho",
"ownerCpf": "123456789",
"password": "123456789",
"botName": "Walle",
"logo": null,
"isActive": true,
"createdAt": "2021-06-26T21:52:03.330Z",
"updatedAt": "2021-06-26T21:52:03.330Z",
"userBranches": [
{
"id": "f7488e1d-5fc4-4314-b7bd-f500e6b77c3f",
"userId": "758406e2-47ce-4f1e-b4be-492103ee2f91",
"managerName": "Leandro",
"branchName": "Quintal da Dirce 2000",
**"countryName": "Brazil"**
"stateId": 1,
"cityId": 1,
"neibourhood": "Minha Kombi",
"street": "rua da kombui",
"streetNumber": "222",
"streetComplement": "222",
"postalCode": "12345",
"isActive": true,
"createdAt": "2021-06-26T21:52:03.347Z",
"updatedAt": "2021-06-26T21:52:03.347Z",
},
Any tips?
In our application we obtain the field values as columns using Spark sql. Im' trying to figure out how to put the columns values to nested json object and push to Elasticsearch. Also is there a way to parameterise values in selectExpr to pass to the regex?
We are currently using the Spark Java API.
Dataset<Row> data = rowExtracted.selectExpr("split(value,\"[|]\")[0] as channelId",
"split(value,\"[|]\")[1] as country",
"split(value,\"[|]\")[2] as product",
"split(value,\"[|]\")[3] as sourceId",
"split(value,\"[|]\")[4] as systemId",
"split(value,\"[|]\")[5] as destinationId",
"split(value,\"[|]\")[6] as batchId",
"split(value,\"[|]\")[7] as orgId",
"split(value,\"[|]\")[8] as businessId",
"split(value,\"[|]\")[9] as orgAccountId",
"split(value,\"[|]\")[10] as orgBankCode",
"split(value,\"[|]\")[11] as beneAccountId",
"split(value,\"[|]\")[12] as beneBankId",
"split(value,\"[|]\")[13] as currencyCode",
"split(value,\"[|]\")[14] as amount",
"split(value,\"[|]\")[15] as processingDate",
"split(value,\"[|]\")[16] as status",
"split(value,\"[|]\")[17] as rejectCode",
"split(value,\"[|]\")[18] as stageId",
"split(value,\"[|]\")[19] as stageStatus",
"split(value,\"[|]\")[20] as stageUpdatedTime",
"split(value,\"[|]\")[21] as receivedTime",
"split(value,\"[|]\")[22] as sendTime"
);
StreamingQuery query = data.writeStream()
.outputMode(OutputMode.Append()).format("es").option("checkpointLocation", "C:\\checkpoint")
.start("spark_index/doc")
Actual output:
{
"_index": "spark_index",
"_type": "doc",
"_id": "test123",
"_version": 1,
"_score": 1,
"_source": {
"channelId": "test",
"country": "SG",
"product": "test",
"sourceId": "",
"systemId": "test123",
"destinationId": "",
"batchId": "",
"orgId": "test",
"businessId": "test",
"orgAccountId": "test",
"orgBankCode": "",
"beneAccountId": "test",
"beneBankId": "test",
"currencyCode": "SGD",
"amount": "53.0000",
"processingDate": "",
"status": "Pending",
"rejectCode": "test",
"stageId": "123",
"stageStatus": "Comment",
"stageUpdatedTime": "2019-08-05 18:11:05.999000",
"receivedTime": "2019-08-05 18:10:12.701000",
"sendTime": "2019-08-05 18:11:06.003000"
}
}
We need the above columns under a node "txn_summary" such as the below json:
Expected output:
{
"_index": "spark_index",
"_type": "doc",
"_id": "test123",
"_version": 1,
"_score": 1,
"_source": {
"txn_summary": {
"channelId": "test",
"country": "SG",
"product": "test",
"sourceId": "",
"systemId": "test123",
"destinationId": "",
"batchId": "",
"orgId": "test",
"businessId": "test",
"orgAccountId": "test",
"orgBankCode": "",
"beneAccountId": "test",
"beneBankId": "test",
"currencyCode": "SGD",
"amount": "53.0000",
"processingDate": "",
"status": "Pending",
"rejectCode": "test",
"stageId": "123",
"stageStatus": "Comment",
"stageUpdatedTime": "2019-08-05 18:11:05.999000",
"receivedTime": "2019-08-05 18:10:12.701000",
"sendTime": "2019-08-05 18:11:06.003000"
}
}
}
Adding all columns to a top level struct should give the expected output. In Scala:
import org.apache.spark.sql.functions._
data.select(struct(data.columns:_*).as("txn_summary"))
In Java I would suspect it it would be:
import org.apache.spark.sql.functions.struct;
data.select(struct(data.columns()).as("txn_summary"));
I am working in elastic search and i have following array in elastic search
{
"took": 101,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 24745,
"max_score": 1,
"hits": [
{
"_index": "users",
"_type": "user",
"_id": "742",
"_score": 1,
"_source": {
{
"id": "1",
"username": "broad",
"full_name": "Bradshaw",
"age": 29,
"gender": "Male",
"followers" : ["2","3","4"]
},
{
"id": "2",
"username": "kevin",
"full_name": "Kevin",
"age": 29,
"gender": "Male",
"followers" : ["1","3"]
},
{
"id": "3",
"username": "john",
"full_name": "John Smith",
"age": 29,
"gender": "Male",
"followers" : ["1","2"]
},
.
.
. and so on
}
]}
Now I want to delete follower two from user 1. Now I am confuse that how I do this I search user 2 but I am unable to update followers of user 1 by delete follower 2 from follower list. Can anyone tell me that what will be the query string of this problem.