wixData.Insert is creating undefined fields.

I’m very new to Corvid but a long-time programmer.

I’m using wixData.Insert to insert a row into a data collection. For some reason, the insert is adding undefined fields of the same name as existing fields, rather than inserting the values into the defined fields.

Example:
The collection contains the field Name .

const toInsert = {
‘_id’: userId,
‘Name’: userName
};

// add the item to the collection
wixData.insert(“MyTable”, toInsert)
.catch( (err) => {
console.log(err);
} );

This executes but instead of assigning the value of userName to the existing column “Name”, Corvid creates a new column called [Name] that is undefined and otherwise inserts a blank row. I’m pretty sure the permissions on the table are correct. I have tried several of the fields in the table with the same result: a new, undefined column is created.

I’m stumped!

Are you sure the case is correct for the column? It might be ‘name’ since the keys generated by the database automatically are typically lowercase.

This is correct. Collection Field Keys are always lowercase, and Field Keys are what is used in a query ( not the Field Name). What happens is that if an insert is performed using a Field Key that does not exist in the collection, a new field is created with the “new” field key in square brackets. Exactly what happened to the O.P.

That makes perfect sense. I can’t believe I didn’t think to use the field key instead of the field name. Thank you very much.