How to delete a element from LIST in dynamoDB - node.js

I have an atrribute with LIST data type be like:
"ketban": {
"L": [
{
"S": "01012018000007"
},
{
"S": "01012018000009"
},
{
"S": "01012018000006"
},
{
"S": "01012018000005"
}
]
}
Now i want to delete a item and result be like:
"ketban": {
"L": [
{
"S": "01012018000007"
},
{
"S": "01012018000009"
},
{
"S": "01012018000006"
}
]
}
I can do it with SET data type but not with LIST data type.
Please help me!!

Related

How to get the Header Row from XLSX Sheet-JS Node module (React)?

I dont understand why the fields of the first row NOT offered in the response?
Ive used this file: file. And Getting the following JSON response upon reading it:
{
"opts": {
...
},
"SheetNames": [
"Dates"
],
"Sheets": {
"Dates": {
"!margins": {
...
},
"A1": {
"v": "Name",
"t": "s",
"w": "Name"
},
"B1": {
"v": "Birthday",
"t": "s",
"w": "Birthday"
},
"A2": {
"v": "George Washington",
"t": "s",
"w": "George Washington"
},
"B2": {
"v": "1732-02-22",
"t": "s",
"w": "1732-02-22"
},
"A3": {
"v": "John Adams",
"t": "s",
"w": "John Adams"
},
"B3": {
"v": "1735-10-19",
"t": "s",
"w": "1735-10-19"
},
"A4": {
"v": "Thomas Jefferson",
"t": "s",
"w": "Thomas Jefferson"
},
"B4": {
"v": "1743-04-13",
"t": "s",
"w": "1743-04-13"
},
"!ref": "A1:B4"
}
},
"Preamble": {},
"Strings": [
...
],
"SSF": {
...
},
"Metadata": {
...
},
"Workbook": {
...
},
"Custprops": {
...
},
"Props": {
...
}
And I created this parsing algorithm:
const getFirstColumnsFromSheet = () => {
const selectedSheetName = "Dates";
return (
selectedSheetName &&
Object.entries(wb['Sheets'][selectedSheetName])
.filter(
(it) => it[0] === it[0].toUpperCase() && /[A-Z]+[1]$/.test(it[0])
)
.map((it) => (it[1] as any)['v'])
);
};
It works fine but its a little try hard, I wonder if there is a simple way to get the column that doesnt include FILTERING - using the uppercase check and if it has the format of "Some letter and the number 1" characters - from ALL the data. (This simply filters out so you only get the fields like :A1,B2,C1,D1 etc...
Is there a more simple solution to this?

Scan for a nested Map inside a List that don't exist

I would like some help with structuring a scan via AWS CLI to get results where the "on_demand" map does not exist. The "on_demand" map is nested in other parent maps [0 , 1, 2...]. Which in turn are in the playlist List.
The conditions for the scan would be where is_offsite = true, video_type = OFFSITE and of course the troublesome condition where the "on_demand" map does not exist.
This is my table structure.
{
"Items": [
{
"playlist": {
"L": [
{
"M": {
"duration": {
"N": "46"
},
"on_demand": {
"M": {
"bucket": {
"S": "s3 Bucket"
},
"key": {
"S": "bucket url to video file"
}
}
},
"download": {
"M": {
"bucket": {
"S": "s3 bucket"
},
"key": {
"S": "bucket url to video file"
}
}
},
"status": {
"S": "on_demand"
}
},
"M": {
"duration": {
"N": "60"
},
"on_demand": {
"M": {
"bucket": {
"S": "s3 Bucket"
},
"key": {
"S": "bucket url to video file"
}
}
},
"download": {
"M": {
"bucket": {
"S": "s3 bucket"
},
"key": {
"S": "bucket url to video file"
}
}
},
"status": {
"S": "on_demand"
}
}
}
]
},
"video_type": {
"S": "OFFSITE"
},
"id": {
"S": "random hash id"
},
"is_offsite": {
"BOOL": true
},
}
]
}
Any assistance will be much appreciated.
This was accomplished by using the following:
aws dynamodb scan \
--table-name table-name \
--projection-expression "id" \
--filter-expression 'is_offsite = :os AND video_type = :vt AND attribute_not_exists(playlist[0].on_demand)' \
--expression-attribute-values '{":os": { "BOOL": true},":vt": {"S": "OFFSITE"}}'

Mongodb, nodejs: find an object and update its value

I am struggling to find a solution to update client's data to the database.
I have a document looking like this:
{
"_id": {
"$oid": "60249fccf992b73b340c7c94"
},
"username": "john",
"inv": {
"id01": {
"n": "Apple",
"r": "0"
},
"id02": {
"n": "Pear",
"r": "0"
},
"id03": {
"n": "Pear",
"r": "0"
},
"id04": {
"n": "GreenApple",
"r": "0"
}
}
}
and this is the json data sent from the client
{
"id02": {
"n": "Pear",
"r": "1",
"z": "-1.0001",
"x": "-2.34",
"y": "-2.41"
},
"id03": {
"n": "Pear",
"r": "1",
"z": "-1.0002",
"x": "-0.52",
"y": "-2.41"
}
}
I want to look for the objects from the json data sent by client in the database (for instance: "id02") and update its value. I am pretty new to Mongodb so I am struggling with finding the proper technique to do so.
The document should be looking like this
{
"_id": {
"$oid": "60249fccf992b73b340c7c94"
},
"username": "john",
"inv": {
"id01": {
"n": "Apple",
"r": "0"
},
"id02": {
"n": "Pear",
"r": "1",
"z": "-1.0001",
"x": "-2.34",
"y": "-2.41"
},
"id03": {
"n": "Pear",
"r": "1",
"z": "-1.0002",
"x": "-0.52",
"y": "-2.41"
},
"id04": {
"n": "GreenApple",
"r": "0"
}
}
}
I try this but it replaces everything in the "inv" with the new data
var addToSet = {};
for(var key in data)
{
addToSet[key] = data[key];
}
db.get().collection('userdata').updateOne({ username: ws.userId},{'$set': {'inv':addToSet}})
I use this :
const Product = require(Path Model Moongose);
const data = {
NameProducts: req.body.title,
TitleProducts: req.body.body,
PriceProducts: req.body.price,
TagesProducts: req.body.tags
};
await Product.updateOne({ _id: Find with your idea }, { $set: data });

Unable to update item on dynamoDb with aws-sdk on node.js

I'm trying to update items on my Users table. emailis my HASH key and id my RANGE
{
"accessToken": {
"M": {
"expirationDate": {
"N": "1622715427"
},
"token": {
"S": "dummy-auth-accessToken-xxx"
}
}
},
"email": {
"S": "xxx#toto.fr"
},
"firstName": {
"S": "Xxx"
},
"id": {
"S": "2"
},
"lastName": {
"S": "Yyyy"
},
"password": {
"S": "tataToto"
},
"refreshToken": {
"M": {
"expirationDate": {
"N": "1622715427"
},
"token": {
"S": "dummy-auth-refreshToken-xxx"
}
}
},
"username": {
"S": "XxxY"
}
}
I would like to update access and refresh token, so i'm doing this:
const dynamoDb = new AWS.DynamoDB.DocumentClient();
const params = {
TableName: 'Users',
Key: { email: 'xxx#toto.fr' },
UpdateExpression: 'set #at1 = :1, #at2 = :2, #at3 = :3, #at4 = :4',
ExpressionAttributeNames: {
'#at1': 'accessToken.token',
'#at2': 'refreshToken.token',
'#at3': 'accessToken.expirationDate',
'#at4': 'refreshToken.expirationDate'
},
ExpressionAttributeValues: {
':1': 'new-dummy-auth-accessToken',
':2': 'new-dummy-auth-refreshToken',
':3': 1234567,
':4': 123456787654
},
ReturnValues: 'UPDATED_NEW'
}
dynamoDb.update(params, (err, data) => {})
but i got:
Unable to update item. Error JSON: {
"message": "The provided key element does not match the schema",
"code": "ValidationException",
"time": "2020-06-03T11:37:57.931Z",
"requestId": "PDTS2SDOEIOPMAO4VHGU6QM21JVV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 27.556977097280456
}
What I'm doing wrong please?
It's my bad... Need to add HASH AND RANGE key on params object
Key: {
id: "2"
email: 'xxx#toto.fr'
}
and my expressions is not good but i know how fix it :)
Ty to read x)

Scanning DynamoDB with ConditionalOperator set to OR is still performing an AND

Per the API Docs I've got the following scan params:
var params = {
"TableName": "MyTable",
"ScanFilter": {
"id": {
"AttributeValueList": [
{
"S": "ID-A"
},
{
"S": "ID-D"
}
],
"ComparisonOperator": "IN"
},
"facilityName": {
"AttributeValueList": [
{
"S": "Name A"
}
],
"ComparisonOperator": "IN"
}
},
"ConditionalOperator": "OR"
};
dynamo.scan(params, function (err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log(JSON.stringify(data, null, 2));
}
});
Regardless of the value in the ConditionalOperator field, the scan always performs an AND. What am I doing wrong?
I would expect with the OR to see ID-A, ID-C AND ID-D. I only ever get ID-D.
If I do a plain or scan, with no ScanFilter setup this is the data:
{
"Count": 4,
"ScannedCount": 4,
"Items": [
{
"facilityName": {
"S": "Name B"
},
"id": {
"S": "ID-A"
}
},
{
"facilityName": {
"S": "Name B"
},
"id": {
"S": "ID-B"
}
},
{
"facilityName": {
"S": "Name A"
},
"id": {
"S": "ID-C"
}
},
{
"facilityName": {
"S": "Name A"
},
"id": {
"S": "ID-D"
}
}
]
}
I am able to use the Java SDK to do what you want:
public static void test() {
ScanRequest scanRequest = new ScanRequest("MyTable");
scanRequest.setConditionalOperator(ConditionalOperator.OR);
Map<String, Condition> scanFilter = new HashMap<String, Condition>();
Condition idFilter = new Condition().withComparisonOperator(ComparisonOperator.IN).withAttributeValueList(new AttributeValue("ID-A"), new AttributeValue("ID-D"));
Condition facilityNameFilter = new Condition().withComparisonOperator(ComparisonOperator.IN).withAttributeValueList(new AttributeValue("Name A"));
scanFilter.put("id", idFilter);
scanFilter.put("facilityName", facilityNameFilter);
scanRequest.setScanFilter(scanFilter);
ScanResult scanResult = dynamo.scan(scanRequest);
for(Map<String, AttributeValue> item : scanResult.getItems()) {
System.out.println(item);
}
}
I am not familar with the JS SDK that you are using. But your code seems OK.
When looking at the js doc, I notcied that ConditionalOperator is introduced in the 2012 version and it is not available in the 2011 version.
Can you verify that you are using the 12 version?

Resources