Query in command must target a single shard key - azure-cosmosdb

I'm trying to insert multiple documents to Cosmos DB with Mongo Api which has a shard key as follows,
insertAll(trips.stream().map(t -> Document.parse(gson.toJson(t))).collect(Collectors.toList()),"trip");
insertAll method is as follows,
private void insertAll(List<Document> data, String collectionName) {
MongoCollection<Document> collection = mongoTemplate.getCollection(collectionName);
collection.insertMany(data);
}
And the documents I'm trying to insert are as follows,
Document{{sensorId=b827ebe942b7, liftId=1edb945b-29e7-c6c7-d20b-87c0, timestamp=1554902007838, ..............}}
Even though I'm providing the shard key which is liftId I get a exception saying single shard key must be provided.
Command failed with error 61: 'query in command must target a single shard key' on server cdb-ms-prod-southeastasia1-fd10.documents.azure.com:10255.
The full response is { "_t" : "OKMongoResponse", "ok" : 0, "code" : 61, "errmsg" : "query in command must target a single shard key", "$err" : "query in command must target a single shard key" }; nested exception is com.mongodb.MongoCommandException: Command failed with error 61: 'query in command must target a single shard key' on server cdb-ms-...-fd10.documents.azure.com:someport. The full response is { "_t" : "OKMongoResponse", "ok" : 0, "code" : 61, "errmsg" : "query in command must target a single shard key", "$err" : "query in command must target a single shard key" }
Any help to fix this? I'm using spring data mongodb

Related

Load JSON File into Robot Framework

I am trying to load a JSON file and use the values to perform some actions based on my tests. I tried to load the json value which I think I got right, but when trying to log the output, I got error message:
Resolving variable '${qa["REQUEST_ID"]}' failed: TypeError: list indices must be integers or slices, not str
Not exactly sure what this means since I am new to Robot Framework. This is what I did to load and log the values:
${file} Get File ${CURDIR}/RequestIDs.json
${qa} Evaluate json.loads('''${file}''') json
Log To Console ${qa["REQUEST_ID"]}
Json file looks something like:
[
{
"REQUEST_ID" : 10513
},
{
"REQUEST_ID" : 48156
},
{
"REQUEST_ID" : 455131
}
]
So basically I want to get the "REQUEST_ID" value and type that in a text field.
Look at the structure of your json - it's a list of dictionaries; so you have to first specify which list member you want, and then its REQUEST_ID field:
Log To Console ${qa[0]["REQUEST_ID"]
# print the value from all present dictionaries in the list:
FOR ${member} IN #{qa}
Log To Console ${member["REQUEST_ID"]
END

dynamodb with help of np dynamodb or np vogels, throwing Invalid schema content error

I am trying to create a schema using node package dynamodb/vogels but it is throwing Invalid schema content. I used the below sample schema
var Account = vogels.define('Account', {
hashKey : 'email',
// add the timestamp attributes (updatedAt, createdAt)
timestamps : true,
schema : {
email : Joi.string().email(),
name : Joi.string(),
age : Joi.number(),
roles : vogels.types.stringSet(),
settings : {
nickname : Joi.string(),
acceptedTerms : Joi.boolean().default(false)
}
}
});
error details
Uncaught Error: Invalid schema content:
node_modules/vogels/node_modules/hoek/lib/index.js:731
Debugger attached.
Waiting for the debugger to disconnect...
c:\my-workspace\dynamoDB\node_modules\vogels\node_modules\hoek\lib\index.js:731
throw new Error(msgs.join(' ') || 'Unknown error');
^
Error: Invalid schema content:
at Object.exports.assert (c:\my-workspace\dynamoDB\node_modules\vogels\node_modules\hoek\lib\index.js:731:11)
at Object.exports.schema (c:\my-workspace\dynamoDB\node_modules\vogels\node_modules\joi\lib\cast.js:65:10)
at internals.Object.keys (c:\my-workspace\dynamoDB\node_modules\vogels\node_modules\joi\lib\object.js:269:25)
at Object.exports.schema (c:\my-workspace\dynamoDB\node_modules\vogels\node_modules\joi\lib\cast.js:46:33)
at internals.Object.keys (c:\my-workspace\dynamoDB\node_modules\vogels\node_modules\joi\lib\object.js:269:25)
at Object.exports.schema (c:\my-workspace\dynamoDB\node_modules\vogels\node_modules\joi\lib\cast.js:46:33)
at internals.Object.keys (c:\my-workspace\dynamoDB\node_modules\vogels\node_modules\joi\lib\object.js:269:25)
at c:\my-workspace\dynamoDB\node_modules\vogels\lib\schema.js:105:74
at internals.Object.internals.Any._validateWithOptions (c:\my-workspace\dynamoDB\node_modules\vogels\node_modules\joi\lib\any.js:460:16)
at module.exports.internals.Any.root.validate (c:\my-workspace\dynamoDB\node_modules\vogels\node_modules\joi\lib\index.js:102:23)
Process exited with code 1
Has anyone come across this or know how to create the schema using node page dynamodb/vogels?

AWS AppSync - DeleteItem doesn't execute response mapping template

When attempting to delete an item using the following request mapping:
{
"version" : "2017-02-28",
"operation" : "DeleteItem",
"key" : {
"id": { "S" : "$ctx.args.id"},
"sortKey" : { "S" : "$ctx.args.sortKey"}
}
}
If the item exists it will process the result through the response template, however when the item does not exist the response template is never run.
Response template:
#set($ctx.result.status = "SUCCESS")
#set($ctx.result.message = "This was a success!")
$utils.toJson($ctx.result)
I am aware that when an item does not exist in Dynamo it will perform no action but I would expect that it would still process through the template.
Is there anything I am missing or is it impossible for AppSync to processed a DeleteItem request through the response mapping when the document does not exist?
This the expected execution behavior for the version of the template you are using (2017-02-28).
You can switch your request mapping template version to 2018-05-29 and your response mapping template will be executed, with the following characteristics:
If the datasource invocation result is null, the response mapping template is executed.
If the datasource invocation yields an error, it is now up to you to handle the error. The invocation error is accessible using $ctx.error.
The response mapping template evaluated result will always be placed inside the GraphQL response data block. You can also raise or append an error using $util.error() and $util.appendError() respectively.
More info https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-changelog.html#aws-appsync-resolver-mapping-template-version-2018-05-29
So for your example:
{
"version" : "2018-05-29", ## Note the new version
"operation" : "DeleteItem",
"key" : {
"id": { "S" : "$ctx.args.id"},
"sortKey" : { "S" : "$ctx.args.sortKey"}
}
}
and response template
#if ( $ctx.error )
$util.error($ctx.error.message, $ctx.error.type)
#end
#set($ctx.result.status = "SUCCESS")
#set($ctx.result.message = "This was a success!")
$utils.toJson($ctx.result)

Mongodb count the number of a field with certain condition

This is the data I have in the database:
{
"_id" : ObjectId("5bf84d5eb6655873af59ead6"),
"game" : 1.0,
"action" : {
"actionType" : "GameStart",
"actionNumber" : 0.0,
"Player1" : {
"user" : 2.0,
"name" : "Kevin"
},
"Player2" : {
"user" : 4.0,
"name" : "Sue"
}
}
}
The question is to report the total number of started games. I tried this code db.hw6.count({'action.actionType': "GameStart" }), and got an error. I have no idea how I did it wrong. can anyone help?
Please use itcount() instead of count to solve the error.
It is because you are using Azure CosmosDB rather than MongoDB. count() will work for mongodb but in your case you should use itcount() which is CosmosDB implementation.
Please refer mongodb documentation. https://docs.mongodb.com/manual/reference/method/cursor.itcount/
Below error will be resolved after using itcount()******
Error: count failed: { "_t" : "OKMongoResponse", "ok" : 0, "code" : 13, "errmsg" : "Cannot execute command ExecuteJavaScript using PrimaryReadonlyMasterKey", "$err" : "Cannot execute command ExecuteJavaScript using PrimaryReadonlyMasterKey" } : _getErrorWithCode#src/mongo/shell/utils.js:25:13 DBQuery.prototype.count#src/mongo/shell/query.js:383:11 DBCollection.prototype.count#src/mongo/shell/collection.js:1700:12 #(shell):

Querying nested values with Q4 2015 version 1.1.3

Based on Tom's answer to this question, I'm getting the following error when trying to query a nested field on a collection.
I'm trying to get a single user object with personalityExams.id.extId = 24232. I'd like to know the best way to query this, and how to form an index rule for it.
Here is what the user looks like in firebase
{
"users": {
"93306b91-d5ba-4e06-838c-0ab85fd58783": {
"createdOn" : 1451495976870,
"email" : "iyad.bitar#gmail.com",
"firstName" : "Iyad",
"lastModifiedOn" : 1451590413654,
"lastName" : "Bitar",
"mobile" : "34234333",
"provider" : "password",
"userType" : "JS",
"personalityExams": [
{
"extId": "24232",
"skills": ["teaching"]
}
]
}
In my javascript, I'm trying to get it like so:
(new Firebase("https://hirely-dev.firebaseio.com/users")).orderByValue("personalityExams/extId").equalTo("24232").on("value", function(snapshot) {user1 = snapshot.val();});
Error:
Uncaught Error: Query.orderByValue failed: Was called with 1 argument. Expects none.
at Error (native)
at x (http://localhost:7200/lib/firebase/firebase.js:20:1074)
at U.g.Fg (http://localhost:7200/lib/firebase/firebase.js:233:343)
at <anonymous>:2:59
at Object.InjectedScript._evaluateOn (<anonymous>:875:140)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:808:34)
at Object.InjectedScript.evaluate (<anonymous>:664:21)

Resources