Hi! How can I correctly scan for two attribute conditions in the same run? When adding a new user to the table, I would like to check if there is already any users with that email or username. I've tried chaining scans but it doesn't seem to work. Also tried the .or() keyword which seems to be only for readability? Putting both attributes in the same scan options would of course just return users that match both conditions.
.scan({
username: {eq: new_user.username}
})
.scan({
email: {eq: new_user.email}
})
.exec()
.then((duplicate_users) => {
console.log(duplicate_users);
//...
Currently I'm doing it this way:
var p1 = User.scan('username').eq(new_user.username).count().exec();
var p2 = User.scan('email').eq(new_user.email).count().exec();
Promise.all([p1, p2])
.then((user_counts) => {
//...
Mongoose schema has the unique: true attribute. That would be nice for Dynamoose as well!
@androidand - First sorry for the slow response.
User.scan(
{
username: {eq: new_user.username},
email: {eq: new_user.email}
},
{conditionalOperator: 'OR'}
).exec()
or
User.scan('username').eq(new_user.username).or().where('email').eq(new_user.email).exec()
Due to the lack of activity I'm closing this issue. Please feel free to comment if this did not solve your problem.
Most helpful comment
@androidand - First sorry for the slow response.
or