top of page

Published: January 22, 2020

Updated: January 22, 2020

7

807

Insert Non-Duplicate Into Wix Database (Corvid)

Category(s)

-Side Menu-
Category

Title

Updated: Nov 1, 2020

Here is the helpful code to get you going! Let me know if you need any more assistance in the comments on YouTube or contact me at the bottom today!

What Was Covered: - Add User Input Fields

- Add a Button

- Create a Wix Data Collection

- Connect Database to User Input Elements

- Add a hook to your database

- Write simple lines of code to not insert duplicate values

- Use Corvid to complete the action

- Test the Before Insert Hook in the Preview Window

 

Code Snippet to follow along with the video:


Backend Code

import wixData from 'wix-data';

export function searchforduplicates(collection, field, item) {

 let options = {
 "suppressAuth": true,
 "suppressHooks": true
    };

 return wixData.query(collection).eq(field, item[field]).find(options).then((results) => {
 return results.items.length
    }).catch((err) => {
 let errorMsg = err;
        console.log(err);
 return Promise.reject('An error occured on wix query')

    })
}

export function event_beforeInsert(item, context) {
 //TODO: write your code here...
 return searchforduplicates(context.collectionName, "email", item).then((res) => {
 if (res > 0) {
 return Promise.reject('This item exist!')
        }
 return item
    })
}

Comments


SIGN UP

Get notified of upcoming articles.

Get Started
View More Categories
Images
Animations
Recent Post

Haga clic aquí para agregar su

propio contenido, o conectarse.

creativelynino_00001.png
YouTube

Haga clic aquí para agregar su

propio contenido, o conectarse.

creativelynino_00001.png
YouTube

Haga clic aquí para agregar su

propio contenido, o conectarse.

creativelynino_00001.png
YouTube

Haga clic aquí para agregar su

propio contenido, o conectarse.

creativelynino_00001.png
YouTube

Did this help?

Yes
No

Thanks, we'll pass on your feedback to improve our services.

Survey
Contact
Feedback

TAKE THE SURVEY

We would love to hear from you.  We strive to create content that is valuable to all persons with and without coding experience.  Please fill out this anonymous survey about your Corvid learning experience.
GET STARTED
bottom of page