Skip to content
Back

Bulk API upsert or Create documents function error

  • 0
  • Functions
  • Flutter
  • Cloud
DeepInsideThe7thPlanet
21 Jul, 2025, 21:15

Hi , I keep getting “databases.upsertDocuments” or “createDocuments” function is not a valid appwrite function error . Following is a simple node.js code (modified for bug reporting purpose) Could you please investigate and let me know the root cause ? Thanks .

Execution id : 687e990ea3b4f735382a

import { Client, Databases, ID } from 'node-appwrite';

export default async ({ req, res, log, error }) => { let payload; try { payload = typeof req.body === 'string' ? JSON.parse(req.body) : req.body; } catch (err) { return res.json({ success: false, error: 'Invalid JSON', data: null }, 400); }

const { ast_id, room_id, type, score } = payload || {};

if (!ast_id || !room_id || !type || !score ) { return res.json( { success: false, error: 'Missing required parameters: ast_id, room_id, type, score, data: null }, 400 ); }

log(submit-prediction: ${JSON.stringify({ ast_id, room_id, type })});

const client = new Client() .setEndpoint(process.env.APPWRITE_ENDPOINT) .setProject( process.env.APPWRITE_FUNCTION_PROJECT_ID || process.env.APPWRITE_PROJECT_ID ) .setKey(req.headers['x-appwrite-key'] ?? ''); const databases = new Databases(client); const dbId = process.env.APPWRITE_DATABASE_ID;

try {

TypeScript
log(`Using score from payload: ${score}`);

const currentDate = new Date().toISOString().split('T')[0];
const documentId = `pred_${ast_id}_${room_id}_${type}_${currentDate}`
  .replace(/[^a-zA-Z0-9_-]/g, '_')


const predictionDoc = await databases.upsertDocuments(
  dbId,
  'predictions',
  [{
    $id: documentId,
    ast_id,
    room_id,
    type,
    score
  }]
);
TL;DR
The developer is encountering an error with the `databases.upsertDocuments` or `createDocuments` function in a node.js code. They are advised to update to `node-appwrite@17.1.0` as `upsert` is not available in the older version `node-appwrite@13`. Additionally, they need to ensure their Node version matches the runtime specified in the Appwrite console. The issue is due to a type error, not an IDE error. The developer needs to check the log and stack trace for more insights.
Kenny
21 Jul, 2025, 21:17

So this is a type error you're getting in your ide?

Kenny
21 Jul, 2025, 21:17

What version of the package are you using?

DeepInsideThe7thPlanet
21 Jul, 2025, 21:30

{ "name": "submit-prediction", "version": "1.0.0", "description": "StarChat prediction submission function", "main": "src/main.js", "type": "module", "dependencies": { "node-appwrite": "^13.0.0" } }

DeepInsideThe7thPlanet
21 Jul, 2025, 21:32

Do we need any specific node version for this to work ?, in the function settings in appwrite console , I have the run time as Node 18.0

DeepInsideThe7thPlanet
21 Jul, 2025, 21:46

That error is not from IDE , that was from Appwrite function logs .

Kenny
21 Jul, 2025, 21:51

Can you provide the log and stack trace

Kenny
21 Jul, 2025, 21:52

that's probably your issue

Kenny
21 Jul, 2025, 21:53

upsert is new and wouldn't be available on an sdk from a year ago

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more