Reputation: 649
I previously used MongoDB and mongoose, now try to implement dynamoose in my app, how to write the same query in dynamoose for below-shown mongoose query?
return this.scan({ abcd: { $ne: null }, activeFlag: true }).skip(9 * (page - 1)).sort({ date: -1 }).limit(9)
I need the same for $ne - not equal to skip sort and also limit
Upvotes: 2
Views: 1910
Reputation: 20546
Dynamoose currently doesn't have support for a skip
function. This is mainly because due to my understanding DynamoDB doesn't have a skip type function on their platform.
For doing something like not equal you can use the .not()
syntax in Dynamoose.
For sorting you have to use the Query.descending()
or Query.ascending()
syntax instead of Scan
.
You can limit the number of items DynamoDB will scan or query by using Query.limit()
or Scan.limit()
. Please keep in mind that this limits the number of items scanned or queried on DynamoDB before any filters are applied. So if you are filtering out items in your scan or query the limit will limit the number of items that even get considered for the filter.
Finally it's important to understand that although Dynamoose was heavily inspired by Mongoose it's not meant to be a plug and play replacement. There are some major fundamental concepts that are very different between MongoDB and DynamoDB, which makes a plug and play system basically impossible.
Therefor I would highly encourage you to read through both the Dynamoose and DynamoDB documentation to understand the benefits and limitations of DynamoDB and ensure it really meets the needs for your given project.
Of course you can do everything you want to do after the results get returned from DynamoDB inside of the Dynamoose callback function by writing your own code, but depending on how many results you have, how many items you have in the table, how fast you need this to be, etc. that might not be a very good option. So although everything you are asking for is possible by writing your own code, there is a chance it won't be as good as MongoDB, and because I don't know MongoDB quite as well as DynamoDB, and because I don't know how those specific Mongoose functions work I can't really speak to that.
Upvotes: 1