nodeJS loopback include filter - node.js

i have a problem with Node JS loop-back include filter when i make a query .Every time its giving all records in response.but i want only those records that holds the sportid which i am passing in query filter.
var request = {
method: 'get',
command: 'UserPersonalinfos',
query: {
filter: {
"include": {
"relation": "UserRegistration",
"where": {
"sportid": data[0].id
}
},
limit:5
}
},
headers: {
access_token:userAccessToken.id,
}
};
if sportid exists then it should return object otherwise it should not, but in this case its returns all UserPersonalinfos records and adding UserRegistration object to UserPersonalinfos object

As per https://stackoverflow.com/a/32933383/344022 there's nothing officially available yet. There is a fork of the loopback-connector by #DiogoDoreto that does attempt to provide it. I haven't tried it, but if you were to use it you would do the following in a filter:
"where": {
"UserRegistration": {
"where": {
"sportid": data[0].id
}
}
}
The answer linked above also suggests some other ways of achieving what you want.

Related

Best solution to TypeORM QueryBuilder combining where methods

I need 'best' solution about this issue.
For example I have these code blocks:
if (search) {
query.andWhere(
'LOWER(task.title) LIKE LOWER(:search) OR LOWER(task.description) LIKE LOWER(:search)',
{ search: `%${search}%` },
);
}
if (search) {
query.andWhere('task.status = :status', { status });
}
This block is working with in order; I mean, first if works first. The second if is working through its result. I want to these ifs will work together and find combining result set.
It can solved like that:
if (search && !status) {
query.where(
'LOWER(task.title) LIKE LOWER(:search) OR LOWER(task.description) LIKE LOWER(:search)',
{ search: `%${search}%` },
);
}
if (status && !search) {
query.where('task.status = :status', { status });
}
if (status && search) {
query.where(
'(LOWER(task.title) LIKE LOWER(:search) OR LOWER(task.description) LIKE LOWER(:search)) AND task.status = :status',
{ search: `%${search}%`, status },
);
}
But I'm not sure about is that best solution.
Anyone has any different solution for this issue?

How to fetch all variants of a product from shopify graphql api?

I want to fetch all variants of a product suing shopify graphql api, but it seems like we have to define the number of variants or any other thing we want by using first argument after the query. I want to get all variants of the product instead of defining a number of variants, how can this be possible?
const myproducts = await axios({
url: `https://${req.session.shop}/admin/api/2022-01/graphql.json`,
method: 'post',
headers: {
"X-Shopify-Access-Token": req.session.token,
},
data: {
query: `
{
product(id: "gid://shopify/Product/6829796196490") {
title
variants(first: 5) {
edges {
cursor
node {
selectedOptions {
name
value
}
media(first: 5) {
edges {
node {
alt
mediaContentType
status
__typename
... on MediaImage {
id
preview {
image {
originalSrc
}
}
__typename
}
}
}
}
}
}
pageInfo {
hasNextPage
}
}
}
}
`,
}
});
A product can't have more than 100 variants, that is a set limit by Shopify.
So in order to get ALL variants you just have to say first: 100 as long as your request cost doesn't exceed the allowed bucket cost for the query you will get them.
As for what you are asking, there is no way to get all variants without using first or last, this is a requirement when you are trying to get an array of edges.

How to resolve Trying to create too many scroll contexts. Must be less than or equal to: [500]?

I'm trying to query from Elastic DB. So for 90000 Records I need to hit elastic DB for two different occasions.My query is as follows.
var queryobj = {
"query": {
"bool": {
"must": [
{
"match": {
"mobile": value
}
}
],
}
}
};
var { _scroll_id, hits, took } = await elasticClient.search({
index: 'mobiledata',
type: '_doc',
scroll: '20m',
filterPath: '_scroll_id,hits.hits._source,took',
size: 10000,
body: queryobj
});
if (hits) {
console.log("hits ", hits);
return hits.hits;
}
return hits;
While trying to exectue this, I'm getting error like :
{ Error: [exception] Trying to create too many scroll contexts. Must be less than or equal to:
[500]. This limit can be set by changing the [search.max_open_scroll_context] setting.
status: 500,
displayName: 'InternalServerError',
message: '[exception] Trying to create too many scroll contexts. Must be less than or equal to:
[500]. This limit can be set by changing the [search.max_open_scroll_context] setting.',
Can anybody help me how to fix this error?
await elasticClient.clearScroll({scroll_id: _scroll_id});
Whenever you want to close the scroll api and open another scroll api, please run the above code.
It works fine for me.

NodeJS How to make a get request with two parameteres in the query

i'm writing a get methode in node js and i have an error when i want get the data base it show me an error that the query return null despite the document exist
router.get('/getmodele',(req,res,next)=>{
let aa=req.query.imei;
console.log(aa);
Post.findOne( {imei: {
'imei.name':req.query.imei,'imei.modele':req.query.modele
},
test: {
$exists: false
}})
.
then((posts) => {
my request take at time two parameteres
i need some helps and thank you
Use dot notation when querying.
Post.findOne( {'imei.name':req.query.imei,'imei.modele':req.query.modele})
I think your query should be like this:
{
imei: {
name: req.query.imei,
modele: req.query.modele
}
}

AWS DynamoDB NodeJS Transactions - Trying to create 'move' with Put & Delete but ValidationError

I'm trying to do a simple transactional 'move' of data from one table to another in DynamoDB (to add indexes). Here's the call I'm making, the promise is returned because I'm using .then() to interpret it, but as you can see from the result I'm getting back there's something wrong with my JSON. Unfortunately, the error message is not very helpful. Very grateful of any help.
var runner = async (column1Value, column2Value) => {
return await ddb.transactWriteItems({
TransactItems: [
{
Delete: {
TableName: 'TABLE_V2',
Key: {
AuthorName: {
S: column1Value
}
}
}
}
,
{
Put: {
Item: {
'AuthorName': {
S: column1Value
},
'AuthorTitle': {
S: column2Value
}
},
TableName: 'TABLE_V3'
}
}
]
}).promise();
}
When I run my code I get the following:
at Request.extractError...
message: 'Transaction cancelled, please refer cancellation reasons for specific reasons [ValidationError, None]',
code: 'TransactionCanceledException',
time: 2019-03-31T00:03:05.401Z,
requestId: 'URIARNJDVFHDVLQQNR1JMIJP5NVV4KQNSO5AEMVJF66Q9ASUAAJG',
statusCode: 400,
retryable: false,
retryDelay: 30.057548210067033
I've read a few sites out there but all refer to a time froms before DynamoDB natively supported transactions with the .transactWriteItems().
e.g.: How to support transactions in dynamoDB with javascript aws-sdk?
Ok, so, there were two issues (let me know if they are not relevant to this site).
The 'Put' error was being thrown by the fact that there was a space character after the column name for the first column: 'AuthorName '
The 'Delete' error was being thrown by the fact that the TABLE_V2 is using not just a primary key but a search key also, so its JSON needs to be:
Delete: {
TableName: 'TABLE_V2',
Key: {
AuthorName: {
S: column1Value
},
AuthorTitle: {
S: column2Value
}
}
}

Resources