Database Insert

Hello everyone,
In my website, there is a lightbox.
What I am trying to achieve is to insert data in to my database.

But when I run the code, it is inserting two fields for the same. Like —

import wixData from 'wix-data';
import wixUsers from 'wix-users';
export function button2_click(event) {
 let user = wixUsers.currentUser;
 let userId = user.id;           
 let isLoggedIn = user.loggedIn;

if (isLoggedIn) {
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
 .find()
        .then((results1) => {
 if(results1.items.length > 0) {

 let toInsert = {
 "fullName":  results1.items.firstName,
 "userId" : userId
  };
  wixData.insert("UserStatuses", toInsert)
    .then( (results) => {
 let item = results; //see item below
    } )
    .catch( (err) => {
 let errorMsg = err;
    } );
            }       
  })
}

}

 

All help is appreciated ,
Ajith

function insertReference (collectionName: string, propertyName: string, referringItem: Object | string, referencedItem: Object | string | Array| Array,[options: WixDataOptions]):Promise< void >

This example inserts a reference to the item with ID 12345 in the Actors field of the item in the Movies collection with the ID 00001.

import wixData from 'wix-data';
2
3// ...
4
5wixData.insertReference("movies", "actors", "00001", "12345")
6  .then( () => {
7    console.log("Reference inserted");
8  } )
9  .catch( (error) => {
10    console.log(error);
11  } );

Whats about the save-function?

import wixData from 'wix-data';
2
3// ...
4
5let toSave = {
6  "title":        "Mr.",
7  "first_name":   "John",
8  "last_name":    "Doe"
9};
10
11wixData.save("myCollection", toSave)
12	.then( (results) => {
13		let item = results; //see item below
14	} )
15	.catch( (err) => {
16		let errorMsg = err;
17	} );

Hai Russian-Dima,
It worked !!!

Can you check on my this post -
https://www.wix.com/corvid/forum/community-discussion/how-to-change-the-value-of-text-in-repeater-automatically

I’m glad to hear that ^^. Have fun!:grin:
I will take a look later.