我正在使用AWS DynamoDB和Dynamoose尝试使用Scan函数获取记录,但面临一个我无法识别的问题。
奇怪的是,它能够以相同的方式从另一个表中获取记录并成功获取记录。
const vehicleMasterSchema = new dynamoose.Schema({
"id": String,
"customer_account_number": String,
"fuel_type": String,
"make": String,
"model": String,
"odometer_gatex": String,
"plate_no": String,
"rfid_gatex": String,
"sales_agreement_id": String,
"vehicle_category": String,
"vehicle_id": String,
}, {
"timestamps": {
"createdAt": "create_date",
"updatedAt": null // updatedAt will not be stored as part of the timestamp
}
});
const vehicleMasterModel = dynamoose.model("vehicle_master", vehicleMasterSchema, { "create": false });
router.post('/getFuelingStatus', (req, res) => {
var companyInfo = req.body;
try {
console.log(typeof vehicleMasterModel); …Run Code Online (Sandbox Code Playgroud) 我使用Dynamoose来简化在 Node.js 应用程序中与 DynamoDB 的交互。我正在尝试使用 Dynamoose 的 Model.query 函数编写一个查询,该函数将使用索引搜索表,但 Dynamoose 似乎不包含处理查询所需的所有信息,我不确定我在做什么做错事。
该架构如下所示:
const UserSchema = new dynamoose.Schema({
"user_id": {
"hashKey": true,
"type": String
},
"email": {
"type": String,
"index": {
"global": true,
"name": "email-index"
}
},
"first_name": {
"type": String,
"index": {
"global": true,
"name": "first_name-index"
}
},
"last_name": {
"type": String,
"index": {
"global": true,
"name": "last_name-index"
}
}
)
module.exports = dynamoose.model(config.usersTable, UserSchema)
Run Code Online (Sandbox Code Playgroud)
我希望能够通过电子邮件地址搜索用户,因此我编写了一个如下所示的查询:
Users.query("email").contains(query.email)
.using("email-index")
.all()
.exec()
.then( results => {
res.status(200).json(results)
}).catch( err => …Run Code Online (Sandbox Code Playgroud) 我需要将用户与发票链接起来。在 SQL 数据库中,它是一个外键。我如何在 Dynamoose 中执行此操作?
const dynamoose = require('dynamoose');
const uuid = require('uuid');
const config = require('../config/config').get(process.env.NODE_ENV);
dynamoose.aws.sdk.config.update({
region: config.awsRegion,
accessKeyId: config.awsAccessKeyId,
secretAccessKey: config.awsSecretKey
});
const userSchema = new dynamoose.Schema({
uid: {
type: String,
hashKey: true,
default: uuid.v1(),
},
name: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password: {
type: String,
require: true
},
token: {
type: String
}
});
module.exports = dynamoose.model('User', userSchema);
Run Code Online (Sandbox Code Playgroud)
其他表中的每条记录的所有者都必须是创建它的用户。
我已经在 GitHub 上打开了一个相关的问题,但也许这里的某个人能够更快地提供帮助。
ValidationException: Query key condition not supported
我需要在给定位置的最后(数量)秒内查找记录。很简单,但已经涉及到的其他问题:
一个和另一个
作品:
Activity.query('locationId').eq(locationId).exec();
不工作:
Activity.query('locationId').eq(locationId).where('createdAt').ge(date).exec();
const Activity = (dynamoose: typeof dynamooseType) => dynamoose.model<ActivityType, {}>('Activity',
new Schema({
id: {
type: String,
default: () => {
return uuid();
},
hashKey: true,
},
userId: {
type: String,
},
locationId: {
type: String,
rangeKey: true,
index: {
global: true,
},
},
createdAt: { type: Number, rangeKey: true, required: true, default: Date.now },
action: {
type: Number,
}, …Run Code Online (Sandbox Code Playgroud) 我目前正在查看 dynamodb 文档,但不清楚哈希键和范围键是什么以及应该如何使用它们。
I just need a basic explanation of what they are and how I am supposed to use them so that I can move forward with using it.
我想从 DynamoDB 的列中搜索(查询)一堆字符串。使用 Dynamoose https://github.com/dynamoose/dynamoose 但它什么也不返回。如果允许这种类型的查询,您可以提供帮助吗?或者是否有其他相同的语法。
代码示例
Cat.query({"breed": {"contains": "Terrier","contains": "husky","contains": "wolf"}}).exec()
Run Code Online (Sandbox Code Playgroud)
我想要所有这些品种,所以这些是 OR 查询。请帮忙。