Sequelizer : JSONB postgres query not working - node.js

I am trying to get the records on the basis of some key that are in jsonb, i am using sequelizer as ORM and postgres as a DB . I am getting empty array of leads unexpected ...
whereArr.push(db.where(
db.cast("dataJson.basicInfo.firstName.value", 'text'),
{ [Op.iLike] : "%k%" }
));
searchBy = {
where: {
...whereArr
}
};
let leads = await Lead.findAndCountAll({
...searchBy,
...orderBy,
...paginate
});
The code work fine if i am using the column name other than jsonb's column .
I am unable to figure out the issue. please guide how can i achieve that .
Thank You

Related

how to use "where" on a query with entity repository from table relations

I am trying to do a query that with query builder works fine but when I try to do it with entity repository fails.
Anyone can tell me what I am doing wrong?
Query Builder query
const dispatchHeader2 = await this.dispatchHeaderRepository.createQueryBuilder('dh')
.innerJoinAndSelect('dh.driver', 'driver')
.innerJoinAndSelect('dh.vehicle', 'vehicle')
.innerJoinAndSelect('vehicle.transportCompany', 'vtc')
.innerJoinAndSelect('dh.order', 'o')
.where('dh.order_id IN(:...ordersId)', { ordersId })
.andWhere('o.local_origin = :selected_dc', { selected_dc })
.getMany()
Query with Entity Repository
const dispatchHeader = await this.dispatchHeaderRepository.find({
relations: ['driver', 'vehicle', 'vehicle.transportCompany', 'order'],
where: {
order_id: In(ordersId),
order: {local_origin:selected_dc }
}
})
Relation on BD
If i do the query without the
order: {local_origin:selected_dc }
works fine, if i Add that line all fails
Thanks for the help.
img from typeorm Docs
Answering Youba
Dont let me do that
And the query doesnt give me an error, just an empty result. But the query itself dont take any parameters

Chaincode can't find index

I'm trying to query the data from CouchDB and have made an index to be able to sort the data.
But no matter what I try, I always get the following error:
Error: GET_QUERY_RESULT failed, No index exists for this sort, try indexing by the sort fields
I have put the index in the META_INF/statedb/couchdb/indexes dir and according the logs is the index successfully created.
This is my query string:
var queryString = {};
queryString.selector = {};
queryString.selector.docType = docType;
queryString.selector.assetId = {"$gt" : null};
queryString.sort= [{assetId : "desc"}];
queryString.limit = 1;
queryString.use_index = ["_design/indexAssetIdDoc" , "indexAssetId"];
and this is the index:
{
"index":
{
"fields":["docType","assetId"]
},
"ddoc":"indexAssetIdDoc",
"name":"indexAssetId",
"type":"json"
}
when using the query and index in the couchdb webapplication is works perfectly.
pictures:
index creation
error

cosmosdb geospatial look up return blank

I am using cosmosDB to do a $geowithin lookup and when i run the query in the cosmosdb data explorer it works fine and returns the right set. When i run it in node js using the MongoClient I get back a empty set.
This is the query i ran in cosmosdb data explorer:
{CurrentLoc: {
$geoWithin: {
$centerSphere: [[-122.0312186,37.33233141], 0.0025232135647961246]
}
}}
That returned the correct list of documents
This is in my node app:
var toFind = {
CurrentLoc: {
$geoWithin: {
$centerSphere: [currentLoc, maxDistance]
}
}
}
var query = db.collection('User').find(toFind)
query.toArray(function (err, doc, queryResult) {
logger.debug ('result: ' + JSON.stringify(doc);
})
That returns a blank set and does not get the data back. Why would it be returning different things and also why is it blank?
You might need to break down the currentLoc variable into an array of two values, so the query is structured in the same manner as when executed through CosmosDB Data Explorer:
[-122.0312186,37.33233141] in
$centerSphere: [[-122.0312186,37.33233141], 0.0025232135647961246]
Hope it helps!

Not able to create index using mongoose

I am building a search feature in a Node.js application which uses Mongoose, creating a full-text search index in Mongo:
postSchema = mongoose.Schema({
xx : String
.......
}).index({
'xx':'text'
});
Post = mongoose.model('Post',postSchema);
And execute the search as follows:
find = {'$text':{'$search':query}};
findScore = {'score':{'$meta':'textScore'}};
sort = {'score': {'$meta':'textScore'} };
Post.find(find, findScore).sort(sort).exec(function (err, data) {
if (err){
logging.log(err);
} else {
logging.log(data);
}
});
When I run the program, I get the following error:
'Unable to execute query: error processing query \n planner returned error: need exactly one text index for $text query'
Any help would be appreciated.
A collection can have at most one text index. You need to check it any of the text index is previously created.

How can i remove element in postgresql json[]

in picture the column node_info was the type of json[], and now i want to
remove one element of the array by Nodejs ORM sequelize
function demo(){
const removeQuery = {
where: {
name: _name
},
raw: true
}
const updateNode = {
node_info: db.sequelize.fn('array_remove', db.sequelize.col('node_info'), JSON.stringify({uuid: uuid}))
}
db.Config.update(updateNode, removeQuery);
}
but i got this error:
ERROR: could not identify an equality operator for type json
Query failed
PostgreSQL said: could not identify an equality operator for type json
I'd appreciate any help you could give me!
Thanks :)

Resources