I understand this may be the stupid question of the week, but I can’t seem to make this work. When performing a database query, I cannot get all the fields to show up in the Record. I am using the standard procedure:
$w("#dataset1").onReady( () => {
let count = $w("#dataset1").getTotalCount();
wixData.query("DailyBetList")
.find()
.then( (results) => {
let allItems = results.items;
allItems.forEach((record) => {
etc. I’ve done it for every other field in the database several times. This leads to an update code, but when inspecting what the record contains after the find - results combination, I do not find the field I wish to update. Originally, it was set up as a ‘number’ field, and the Update function gave me this error:
Error: Invalid update. Updated object must have a string _id property.
I checked the database and changed the original field from ‘number’ to ‘text’, but the error persisted. So I removed that field and created a new one as text from scratch and the error persists. All fields are in ‘text’ format now.
here’s the complete code I am working on:
export function UpdateRowNumbers_click(event) {
//Add your code for this event here:
$w("#dataset1").onReady( () => {
let count = $w("#dataset1").getTotalCount();
let rowNumber = 0;
wixData.query("DailyBetList")
.find()
.then( (results) => {
let allItems = results.items;
allItems.forEach((record) => {
if (rowNumber === 0 || rowNumber < count){
rowNumber = rowNumber+ 1;
var rowNumber1 = rowNumber.toLocaleString();
}
allItems.hiddenRowCount = rowNumber1;
console.log("this is rownumber", allItems.hiddenRowCount);
///updating database with results
let Id = allItems._id;
let b_leagueTournament = allItems.leagueTournament;
let b_RecommendedBet = allItems.recommendedBet;
let b_playerTeamOne = allItems.playerTeamOne;
let b_playerTeamTwo = allItems.playerTeamTwo;
let b_recommendedBetOdds = allItems.recommendedBetOdds;
let b_createdDate = allItems._createdDate;
let b_HFR = allItems.hiddenFinalResults;
let b_finalResults = allItems.finalResults;
let b_profitLoss = allItems.profitLoss;
let b_sumProfitLoss = allItems.sumProfitLoss;
let b_rowNumber = allItems.hiddenRowCount;
console.log(record);
let toUpdate = {
"_id": Id,
"leagueTournament": b_leagueTournament,
"recommendedBet": b_RecommendedBet,
"playerTeamOne": b_playerTeamOne,
"playerTeamTwo": b_playerTeamTwo,
"recommendedBetOdds": b_recommendedBetOdds,
"hiddenFinalResults": b_HFR,
"_createdDate":b_createdDate,
"finalResults":b_finalResults,
"profitLoss":b_profitLoss,
"sumProfitLoss":b_sumProfitLoss,
"hiddenRowCount":b_rowNumber
};
updateBet(toUpdate);
});
} )
.catch( (err) => {
let errorMsg = err;
} );
});
}
the field ‘hiddenRowCount’ does not appear in the record when the query is run, so I think there is something that is making the darn thing be invisible to the query, but I have no idea what that might be. No errors appear at the line level, so it seems that it all looks good, but the field does not show up on the record, these are the fields and the test data that show up when the query is run:
_id:
"9f058c9c-11da-4dd7-99af-8d92f220ac88"
leagueTournament:
"another test"
recommendedBet:
"another one"
playerTeamOne:
"another one"
playerTeamTwo:
"another two"
recommendedBetOdds:
"1.3"
hiddenFinalResults:
"1"
_createdDate:
"2018-11-23T09:00:44.286Z"
finalResults:
"Win"
profitLoss:
"0.30"
sumProfitLoss:
"1.29"
_owner:
"b898fb7f-6157-41b4-a709-ec24fed911fc"
_updatedDate:
"2018-11-27T12:54:35.898Z"
Suggestions on reasons why the field does not appear in the record will be deeply appreciated so I can test them out.
Thank you.