The wix-data reference data (https://www.wix.com/corvid/reference/wix-data.html) says that if your dataset does not have an _id field you can manually assign one but it does not state how to assign that. I have a dataset that keeps giving an error when I try to run a filter on it saying that it has no _id property. I manually added a _id field and numbered each row sequentially for an index but wix is not recognizing that as the actual _id property since I am still getting that error. How to I manually assign which field is the _id property?
Yes it does.
Insert an item with a specified ID into a collection
import wixData from 'wix-data';
// ...
let toInsert = {
"_id": "00001",
"title": "Mr.",
"first_name": "John",
"last_name": "Doe"
};
wixData.insert("myCollection", toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
/* item is:
*
* {
* "_id": "00001",
* "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
* "_createdDate": "2017-05-24T12:33:18.938Z",
* "_updatedDate": "2017-05-24T12:33:18.938Z",
* "title": "Mr.",
* "first_name": "John",
* "last_name": "Doe"
* }
*/
Insert an item into a collection using data options
import wixData from 'wix-data';
// ...
let toInsert = {
"_id": "00001",
"title": "Mr.",
"first_name": "John",
"last_name": "Doe"
};
let options = {
"suppressAuth": true,
"suppressHooks": true
};
wixData.insert("myCollection", toInsert, options)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
/* item is:
*
* {
* "_id": "00001",
* "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
* "_createdDate": "2017-05-24T12:33:18.938Z",
* "_updatedDate": "2017-05-24T12:33:18.938Z",
* "title": "Mr.",
* "first_name": "John",
* "last_name": "Doe"
* }
*/
Insert multiple items with specified IDs into a collection
import wixData from 'wix-data';
// ...
let toInsert1 = {
"_id": "00001",
"title": "Mr.",
"first_name": "John",
"last_name": "Doe"
};
let toInsert2 = {
"_id": "00002",
"title": "Ms.",
"first_name": "Jane",
"last_name": "Doe"
};
wixData.bulkInsert("myCollection", [toInsert1, toInsert2])
.then( (results) => {
let inserted = results.inserted; // 2
let insertedIds = results.insertedItemIds; // ["00001", "00002"]
let updated = results.updated; // 0
let skipped = results.skipped; // 0
let errors = results.errors; // []
} )
.catch( (err) => {
let errorMsg = err;
} );
I apologize I didn’t read that close enough. I thought it was talking about assigning a specific column as your _id property. I added a column to my dataset with the name _id with sequential numbering but when I try to search my dataset I get an error saying " Expected hook result to resolve to an object with an ‘_id’ property, but got an object without the ‘_id’ property ". Is there a way to direct WIX to see this column as the _id property?