Query 1: java.lang.ArrayIndexOutOfBoundsException - cassandra

When I run this query :
SELECT * FROM recipient WHERE expr(recipient_index, '{
sort:{field: "fname", reverse: true }
}');
I am getting the below error in cassandra:
Query 1: java.lang.ArrayIndexOutOfBoundsException
But if I run the same query in other table it is working fine.
Can some look into this give the result please why this is happening only in the single table.

Related

[Op.like]: example from Sequelize documentation throws SQL error

I have a Node/Express/Sequelize project.
Using the following example from the documentation, it fails and throws a SQL error on MySQL
Image.findAll({
where: {
image_title: {
[Op.like]: { [Op.any]: ['cat', 'hat']}
}
}
})
The above query generates the following SQL in Node/Express:
`Executing (default): SELECT `id`, `story_title`, `image_title`,
`original_filename`, `created_at` AS `createdAt`, `updated_at`
AS `updatedAt` FROM `image`
AS `image`
WHERE `image`.`image_title` LIKE ANY ('cat', 'hat');`
I expected to get a list of images where the image_title contains either 'cat' or 'hat'
Instead, I get a console error in Chrome that reads:
"You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax
to use near '('cat', 'hat')' at line 1"
And no images.
What I'm trying to do is pass an array of strings into a query and return all images where the image_title contains any of the strings in the array.
This example from the documentation seems to be exactly what I'm looking for, but I can't get it to work with even static strings using the documented syntax.
Is there a bug in this, am I misunderstanding how this works, or is there another way to accomplish this?
Possible workaround for now might be to use RegEx
let words = ['cat','hat'];
Image.findAll({
where: {
image_title: {
[Op.regexp]: `*(${words.join('|')})*`
}
}
})

Error : Writing in a non-empty collection

I have been facing issue while writing json to my Cosmos DB. I could able to read data and having an issue while writing the same
An applied following version of Cosmos db connectors
https://docs.azuredatabricks.net/spark/latest/data-sources/azure/cosmosdb-connector.html
and tried different versions too. The issue remains to persist.
RawFilePath="/mnt/ADLS/Users/test/CosmosDB/testfile.json"
DFRead=spark.read.json(RawFilePath)
DFNew = DFRead.selectExpr("activity", "partition AS xfactor","response", "source", "type")
writeConfig = {
"Endpoint" : "{End Point}",
"Masterkey" : "{MasterKey}",
"Database" : "{DB Name}",
"Collection" : "{Connection name}",
"Upsert" : "true"
}
DFNew.write.format("com.microsoft.azure.cosmosdb.spark").options(**writeConfig).save()
Getting the following error.
Error : java.lang.UnsupportedOperationException: Writing in a non-empty collection.
Expecting to write json into cosmos DB collection. But, could not able to resolve non-empty collection error in Databricks. Its really appreciate your help.
thank you..
Try by specifying mode
DFNew.write.format("com.microsoft.azure.cosmosdb.spark").mode("append").options(**writeConfig).save()

Unhandled rejection MongoError: The dollar ($) prefixed field '$inc' in '$inc' is not valid for storage

I am getting following error while i am trying to increment a field by a specified value in mongodb using $inc
"Unhandled rejection MongoError: The dollar ($) prefixed field '$inc' in '$inc' is not valid for storage."
Below is my code
APILog.update({ apiId: 1 }, {$inc:{"dataCount":10}});
Thanks in advance
You should include values as JSON in Mongo Query. Might be due to this you are facing an issue. Can you please try by updating your query as:
APILog.update({
"apiId": 1
},
{
"$inc": {
"dataCount": 10
}
})
I ran into same exception and was able to solve this way.
Following is the syntax of executing a general command in mongodb, updated with your example data:
db.runCommand(
update: "<replace-with-collection-name>",
updates: [
{
q:{"apiId": 1}, u: {"$inc": {"dataCount": 10}}
}
]
)
Escape the $ character as per rules of node.js, if needed.
Since I came across this... I've found at least for me that it works to use brackets if you're doing an aggregation inside your update. Like so:
db.example.updateMany(
{FirstRecord:{$in:recordids}},
[{$set:{
RecordCode:{
$first:{
$map:{
...
}
}
}
}}]
)
In my case I'm trying to update a field which is a code we will use later to match to other documents, and have a list of ObjectIds for the target records and a dictionary from ID to code. Anyway I found I received a similar error until I added the brackets around [{$set:{}}]

NetSuite SuiteScript 2.0 getSelectOptions filter breaks setValue

I am dumbfounded on what is happening and hoping someone can help me figure out what is happening. I am using SuiteScript 2.0 and to find the internal id's of dynamic fields I am doing:
var location = saleRec.getField({
fieldId: 'location'
}).getSelectOptions({
filter: "Test Location",
operator: 'is'
});
This returns the internal ID I need but when I try to call:
saleRec.setValue({
fieldId: 'location',
value: location[0].value
});
I get an error:
{
"error": {
"code": "JS_EXCEPTION",
"message": "{\"type\":\"error.SuiteScriptError\",\"name\":\"INVALID_FLD_VALUE\",\"message\":\"You have entered an Invalid Field Value 2 for the following field: location\",\"stack\":[\"anonymous(N/recordService)\",\"doPost(SuiteScripts/DemoProject/RESTlet1.js:124)\"],\"cause\":{\"type\":\"internal error\",\"code\":\"INVALID_FLD_VALUE\",\"details\":\"You have entered an Invalid Field Value 2 for the following field: location\",\"userEvent\":null,\"stackTrace\":[\"anonymous(N/recordService)\",\"doPost(SuiteScripts/DemoProject/RESTlet1.js:124)\"]},\"id\":\"\"}"
}
}
The number 2 is definitely the internal ID I need. But it starts to get weird. If I remove the filter and just call:
var location = saleRec.getField({
fieldId: 'location'
}).getSelectOptions();
And then loop through the array of results and select the proper internal id I need everything works fine and it is able to set the internal id of location. It seems like the filter is removing it from the location select field or something strange like that but I can't imagine that is the intended purpose of the filter. Is this a bug or am I using it wrong?
Just a hunch, try running again
.getSelectOptions({filter: "Test Location",operator: 'is'}).
Then after getting the value
.getSelectOptions();
It seems like a bug, where the data object holding the available values is left filtered.

nodejs mongodb find modify and return new. Can't canonicalize query

My question is related to this
findAndModify Error in mongodb - nodejs - error code 17287
But the solution hasn't worked (i tried specify the order but i get the same error) I think it might be something along the lines of the index I am using example instead of _id (_id is a field in this collection I just don't want to search by _id in this case) not sure at all...
The Error:
{ [MongoError: exception: nextSafe(): { $err: "Can't canonicalize query: BadValue bad sort specification", code: 17287 }]
name: 'MongoError',
message: 'exception: nextSafe(): { $err: "Can\'t canonicalize query: BadValue bad sort specification", code: 17287 }',
errmsg: 'exception: nextSafe(): { $err: "Can\'t canonicalize query: BadValue bad sort specification", code: 17287 }',
code: 13106,
ok: 0 }
This is my code, it should find and modify (and return using new:true) the first instance of a document that has the field example equal to minus one.
db.collection('documents').findAndModify({example:-1},{$set:{example:0}},{new:true},function(err,result){
console.dir(err||result);
});
But all it does is error like it hates my face!
Here is a document:
{'_id':0,'example':-1}
My id field is custom numerical Where I ensure the _id is always unique (For my purposes I cannot change the _id to standard mongodb way.)
It was painful to get this to work as the node docs end abruptly and then you are left guessing on how the code structure should be on what would/could of just been a standard structure but isn't! I have wasted a day thanks to the devs undocumented methods.
Here is the working code
db.collection('documents').findAndModify({'example':{$eq:-1}},[['example',1]],{$set:{'example':-1}},{'new':true},function(err,result){
console.dir(err||result);
});
I am not sure I really like writing code like this ether. I might look for another node module for this as the query above looks disgusting!
Would be greate if I could find something that looks as simple as this:
db.collection('documents').findModifyReturn('find:example==-1;order:asc;set:example=0;',function(e,r){});
Try using the $eq operator.
db.collection('documents').findAndModify({example: {$eq: -1}}, {'example', 'ascending'},{$set:{example:0}},{new:true},function(err,result){
console.dir(err||result);
});

Resources