Parse Server Upgrade to v4.2: Unable to ensure uniqueness for user email addresses - mongodb

I have recently upgraded parse-server to v4.2. I have also updated Mongo to v4.2 (It's a Replica Set configuration). Now when parse-server is raised, the following error appears "Unable to ensure uniqueness for user email addresses: Tried to ensure field uniqueness for a class that already has duplicates."
The detailed error is this:
{
"message": "Unable to ensure uniqueness for user email addresses: Tried to ensure field uniqueness for a class that already has duplicates.",
"code": 137,
"level": "warn",
"stack": "Error: Tried to ensure field uniqueness for a class that already has duplicates.\n at _adaptiveCollection.then.catch.error (/parse/node_modules/parse-server/lib/Adapters/Storage/Mongo/MongoStorageAdapter.js:569:15)\n at <anonymous>\n at process._tickDomainCallback (internal/process/next_tick.js:229:7)"
The error is caused by the _User class that has the username and email fields with the same data.
Any ideas on how to fix the problem or make the parse-server not do this check.

The error message means that a unique index could not be created on the email field.
The unique index ensures that in the email field a value can only occur once, in other words, that it occurs uniquely. MongoDB cannot create such an index if there are already duplicate values in the email field that would violate the rule of uniqueness, in other words, an identical email address already appears multiple times in the collection.
Keep in mind that Parse Server 4.0 introduced a case-insensitive index for the the field email and username. If you already have a user with email email#example.com and another one with EMAIL#example.com, the index creation will also fail.
The solution is to remove the duplicate email entries and restart Parse Server, so that index creation will be attempted again.

Related

How to change domain of a field in IBExpert?

I wanted to change a field from D_ALPHA2NOTNULL to D_ALPHA8NOTNULL, so that I am able to use more chars. Unfortunately if I am trying to change the domain I am getting an error message:
action cancelled by trigger (2) to preserve data integrity.
Cannot update index segment used by an Integrity Constraint.

Insert Item Atomicity

I'm trying to create a new account with unique email. One of the options is to check if there is an account with the same email already exists. If there is none, create the new account.
Account
.find({email: req.body.email})
.exec((err, accounts) => {
//Try to find an account that have the same email
if (!accounts.length) {
//If none is found create a new account with this email
var account = new Account({email: req.body.email});
account.save();
}
});
The problem with this approach is that I am unclear about whether this is atomically-safe or not. What if multiple users trying to create a new account with the same email at the same time. Will that ruin the consistency of my database ?
I've heard about the unique option in SchemaType.
Should I go with that option instead ?
Is using the mongoose built-in validation a must ? Other options ?
Is the above code considered bad practice ?
This will not be atomically safe in MongoDB. You can however use a unique index on the email field. This will cause an insert to fail if it was used already or if someone just inserted it concurrently.
If you plan on using sharding this can become a problem because unique indexes are only supported on shard keys.

Laravel 5.1 Reset Password Function; user's email is in a different table

I have a question regarding Laravel's Reset Password function. I have thoroughly searched for a possible solution and could not find one. Moreover, I tried to scrutinize the code and manually implement it, but failed miserably because of the nesting. (I'm new to Laravel).
According to Laravel's documentation, the user's email must be in the table user in order to work and the error code confirms it.
*Column not found: 1054 Unknown column 'email' in 'where clause' (SQL: select * from user where email = usermail#provider.com limit 1*
However, we do have the scenario that an user might have multiple email addresses, hence stored in a different table called user_email.
Does anybody have experience with this scenario and could take the time to enlighten me on this?
You have two Options:
Write your own password recovery system.
Let the user choose a primary e-mail and make a column on the users table which represents the primary e-mail adresse.

SugarCRM related Field

I have sugarCRM 6.5.20 OnDemand. I am in the Studio. I have a 1:1 relationship from Leads to Leads. I am trying to get the Primary Email address of the related Lead and display it in a calculated field.
It seems like the calculated field formula should look like:
related($emails,"email1")
When I do that I get the following error:
Invalid formula: related: Unknown Field : email1
The dropdown list doesn't list the email at all. How can I get the email? All of my web searches have proven ineffective.
Update:
I am willing to make the calculated field be the primary email address of the current lead. To do that I found 2 variables named $email_addresses and $email_addresses_primary and $emails. There is also a function called valueAt.
I tried to use valueAt(1,$emails) and valueAt(1,$email_addresses)
The validator accepted the syntax but the value was always empty.
Can I make a calculated field off of the leads primary email?
You won't get the Email field for the Studio's formula calculation. Email field is stored in a separate table and not in the module's table. It is just put in the Layout along with the other fields of the module, but it is not the same as other fields. All the Email Addresses irrespective of the modules are stored together in the email_addresses table and are related to respective module records in the email_addr_bean_rel.

Issue with Vendor and Employee Business Rules

According to the documentation, there is a Business Rule for Vendor and Employee that says
The name, first name, or last name field should not be blank.
Considering that NAME is required for create, the question is ¿Does this mean that ALL three properties have to have a value on Create?
We understood that, so we ran some tests. Creating a record with the three properties populated has no problem. The issue comes when we try so insert a null value for GivenName and FamilyName (first name and last name).
Quickbooks seems to take the NULL values as valid, and when inserting the record is not returning any error. The problem is that the record that was inserted never shows in the QBD UI, but is seems like it persists somewhere, because if we try to insert it again we get a "duplicate name" error.
Not sure if this is an issue or an expected behaviour... Any hints??
Thanks
QuickBooks for windows has some legacy behavior to be aware of. The First, Last and Name combines for a unique identifier accross Customers, Vendors and Employees. So you should fill in ALL the information you have. Any attempts to insert a record with the same F or L name, will fail if there is a Customer, Vendor or Employee with the same F & L.
Second, you mentioned that the record doesn't show in QuickBooks for Windows?
Did it sync successfully? Did you check the error state of the record you inserted?
Did you look at the sync logs to see if it failed to sync?
Lastly, you need to check all three objects for a user with the same F & L name if you are getting a duplicate error. Normally you would check to see if the customer/vendor/employee exists firsts so you can update the existing or determine if it is in fact a new record.
hope that helps
Jarred