dynamoose | Dynamoose is a modeling tool for Amazon 's DynamoDB | AWS library
kandi X-RAY | dynamoose Summary
kandi X-RAY | dynamoose Summary
Dynobase helps you accelerate your DynamoDB workflow with code generation, faster data exploration, bookmarks and more:
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Main entry point .
- Redirect to the home page .
dynamoose Key Features
dynamoose Examples and Code Snippets
Community Discussions
Trending Discussions on dynamoose
QUESTION
I have created a model that was working when I had my backend functions running on my local machine, but when it uses AWS I get and authentication problem when the table is being queried:
...ANSWER
Answered 2022-Feb-18 at 15:23Disclaimer: this answer is based on Dynamoose v3.0.0 beta 1. Answers based on beta versions can become outdated quickly, so be sure to check for any updated details for your version of Dynamoose.
In Dynamoose v3, a new class was introduced called Table
. This represents a single DynamoDB Table. In previous versions of Dynamoose, a Model
represented a single DynamoDB Table, but based on the API also kinda represented a specific entity or model in your data structure (ex. Movie, Order, User, etc). This lead to complications and confusion when it comes to single table design structures especially.
In terms of code, what this means is the following.
QUESTION
I am using Amazon DynamoDB for the database and am looking to go with a single table design.
My data types is Users, Posts, Categories, Comments, etc. I can get posts list but I need to get posts and user (author) data for each post (e.g firstName, lastName and etc)
Access patterns are expected to be as follows:
Fetch a user by its ID (Done)
- Get all users (Done with
userStatusIndex
) - Get all posts by category Id (Done)
- Get all posts for a user: I can get the posts list with
publishStatusIndex
but I need author info and categories details, too. (Author info and categories details for each post) - Get all posts for all users: (The above case)
I'm using Dynamoose:
...ANSWER
Answered 2021-Sep-27 at 18:19NoSQL databases will often require you to denormalize your data to meet the access patterns of your applications. In other words, if you want this response:
QUESTION
Here's my dynamoose schema for table seller
ANSWER
Answered 2021-Jun-27 at 01:34As descrribed in the Dynamoose documentation, where
takes in a key attribute. This key represents an attribute name (SK
), not an index name (SKIndex
).
Changing your code to the following should work.
QUESTION
I'm starting to learn Dynamodb here, and currently trying to do a search on my table where PK is the partition key and SK is the range key. PK contains an email address, whereas SK contains value like AB_STATE
, BC_STATE
, MY_STATE
. So I want to search in the SK where the value starts with MY_
but I'm not entirely sure how to do it using .get()
function.
Here's my query Seller.get({ "PK": "imin@cats.com", "SK" : "MY" })
which obviously isn't doing what I wants.
I am aware that I maybe can use filter like below, but I read in many places that using filter is not recommended (?)
...ANSWER
Answered 2021-Mar-23 at 14:22When doing a Model.get
call you must pass in an entire key. You can not pass in a key that starts with. This is due to the fact that Model.get
will only return 1 item, and the query indicates that you could have multiple items there.
It's hard to answer your question exactly due to the fact that you didn't post your schema. But it looks like doing a query
in this case isn't bad due to the fact that you are querying the data as opposed to filtering it.
Little bit more information based on comments.
I realized the condition.filter
documentation doesn't really cover this as well as it should. Basically depending on your schema, it will determine the best index, and optimize it the best way it knows how.
For example, if you have the following code:
QUESTION
We are creating DynamoDB tables in AWS using terraform.
Our application is a Nest.js application using nestjs-dynamoose and is deployed as a Lambda function. The lambda function is started without any error. The create option in dynamoose is set to false.
When trying to access the created tables the this.model.get([...]) never finishes:
...ANSWER
Answered 2021-Mar-19 at 20:22For Models there are two settings you can set: create
& waitForActive
. It sounds like your table is fully created, active, and ready to go.
If you set both of those settings to false
this should work as you expect.
Here is an example of some code to achieve that:
QUESTION
I have a dynamodb
table that I declared using dynamoose
as below:
ANSWER
Answered 2020-Dec-13 at 00:19Based on the comment from the original poster. It looks like this is only occurring for the update
call.
There isn't quite enough information in the original question for me to give a concrete answer as to what I believe is the best solution. So I'm going to make a few assumptions, and give a lot of high level detail about how Dynamoose handles this situation.
Just a little bit of the behind the scenes which will help make my answer more clear. From Dynamoose's perspective, it has no idea if the document/item already exists in the database or not. That leads to a situation where createdAt
is difficult to get 100% accurate. You are running into one of these situations. For the update
call, Dynamoose assumes that the document already exists, and therefore doesn't set the createdAt
timestamp. This makes sense because createdAt
doesn't really match with an update
call. However, DynamoDB & Dynamoose technically allows for using update
to create a new document/item. But Dynamoose has no way of knowing which it is, so we use the behavior of assuming update
means not creating a new document for this context.
As for a possible solution. You have a new
variable. I'm curious how you are defining that variable. One option would be to check the table using a get call and see if the document already exists. If you do that as your new
variable, it should work fine. Because it will save if it doesn't exist, and if it already exists, it should have the createdAt
variable already. Major downside to this is that you have to always do a read operation before writing. Which increases the latency of the application, and slows things down. But it will achieve what you want.
Now. In the event you have documents in your table that don't have the createdAt
timestamp (ex. you created it outside of Dynamoose, or you created it before adding the timestamp option), the above solution won't work. This is because even checking to see if it exists, will cause the update
method to be run, which Dynamoose assumes to be an update not a creation. In this case, any solution is really dependent on what your application wants to do. The item already exists in the table, so it's impossible to know when the true createdAt
timestamp was (unless you keep logs and all that). You could run a one time operation to go through and add the current timestamp to the createdAt
field if it doesn't have it for each document (but again that won't be truly accurate). Or of course you could just ignore it, and not rely on that field always.
To summarize, the timestamps feature in Dynamoose is truly a client side feature. Dynamoose has limited insight into the state of the data, and DynamoDB doesn't provide this functionality built in. This means Dynamoose has to make assumptions about how to handle these situations. However, if you follow Dynamoose's patterns for timestamps (ex. update
won't add the timestamp and should only be used for updating existing items, creating all items in Dynamoose, etc), it will be totally accurate, and you won't run into any of these pitfalls.
If you have any creative solutions for how to improve Dynamoose's knowledge here, feel free to create a pull request on the repo or create an issue to discuss your ideas.
QUESTION
I am working with AWS DynamoDB and Dynamoose trying to fetch records using Scan
function, but facing an issue that is not recognizable for me.
Stragenly, it's able to fetch records from another table in the same way and successfully get the records.
Here's my Code: ...ANSWER
Answered 2020-Nov-15 at 14:11My guess is that the problem could be related with the name of your attribute, model
.
In fact, this is the actual case: the following code, extracted from the source code in Document.ts
is the one which is overwriting your model
property:
QUESTION
I'm trying to migrate my mongoose code/db to dynamoose/dynamodb.
I get the following exception while trying to save custom object:
TypeMismatch: Expected name to be of type object, instead found type object
Here is my sample code on nodejs / typescript:
...ANSWER
Answered 2020-Nov-12 at 21:22I got it working using this as identified in this issue on Github:
QUESTION
When I tried to run my lambda function register
which queries the table example_user
, it will throw the error below. My code is only trying to get data from the table example_user
and not create any table.
{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"AccessDeniedException: User: arn:aws:sts::577777777777:assumed-role/example-user-api-dev-ap-southeast-1-lambdaRole/example-user-api-dev-register is not authorized to perform: dynamodb:CreateTable on resource: arn:aws:dynamodb:ap-southeast-1:577777777777:table/example_user","reason":{"errorType":"AccessDeniedException","errorMessage":"User: arn:aws:sts::577777777777:assumed-role/example-user-api-dev-ap-southeast-1-lambdaRole/example-user-api-dev-register is not authorized to perform: dynamodb:CreateTable on resource: arn:aws:dynamodb:ap-southeast-1:577777777777:table/example_user"
The error was thrown after 13 UserController with email
This is my codes:
User.js
ANSWER
Answered 2020-Oct-31 at 12:32You should be able to do dynamoose.model('example_user', schema, {"create": false})
to get away from the need to create a table https://dynamoosejs.com/guide/Model/
QUESTION
I need dynamoose query equivalent to this SQL query
select * from employees where first_name like '%fish%' or last_name like '%fish%'
.
I tried below code but doesn't work.
...ANSWER
Answered 2020-Oct-30 at 12:19this works for me!
const employees = EmsModel.query('pk') .eq('emp_prof') .and() .parenthesis(new dynamoose.Condition().where('first_name').contains(param).or().where('last_name').contains(param)) .exec();
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install dynamoose
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page