Here you have to use + between parameters, logger.info logs only the first parameter
it may fail here if it tries to check fi the email is valid
you could try first with another field
I tried with updating a different field as well and no luck either
it looks like cloud code on your server doesnāt work now (because of syntax error somewhere)
can you run a simpler cloud function that only logs something?
Hi @snuffle
Try this
user.save(null, { useMasterKey: true }).then((monster) => {
// The object was saved successfully.
}, (error) => {
// The save failed.
// error is a Moralis.Error with an error code and message.
});
Now what I have is the following, and nothing logs to the moralis logs, nor saves The fields āfullNameā is just a normal string field.
Moralis.Cloud.define("TrackProgress", (request) => {
let userQuery = new Moralis.Query(Moralis.User);
userQuery.equalTo("objectId", request.params.user_id);
userQuery.first({useMasterKey: true,
success: function (user) {
user.set("fullName", "test");
user.save(null, { useMasterKey: true }).then((result) => {
// The object was saved successfully.
logger.info("success saving user");
}, (error) => {
// The save failed.
// error is a Moralis.Error with an error code and message.
logger.info("error saving user");
});
},
error: function (error) {
logger.info("error grabbing user");
},
});
});
Try to add a log line on the first line of the function. To know at least that it was called.
@cryptokid with the below code, only the line āgot hereā is logged in moralisā dashboardā¦
Moralis.Cloud.define("TrackProgress", (request) => {
logger.info("got here");
let userQuery = new Moralis.Query(Moralis.User);
userQuery.equalTo("objectId", request.params.user_id);
userQuery.first({useMasterKey: true,
success: function (user) {
logger.info("got here 2");
user.set("fullName", "test");
user.save(null, { useMasterKey: true }).then((result) => {
// The object was saved successfully.
logger.info("success saving user");
}, (error) => {
// The save failed.
// error is a Moralis.Error with an error code and message.
logger.info("error saving user");
});
},
error: function (error) {
logger.info("error grabbing user");
},
});
});
Can you try to use try to see if there is any exception?
You can also try a syntax with await
You can also log this user_id value to see if it is the expected value
@cryptokid when i log out user id, it logs just fine, again, no errors even logged with below codeā¦
and even when i wrap the userQuery.first in a try/catch block, it never even get to the catchā¦ fails silently
Moralis.Cloud.define("TrackProgress", (request) => {
logger.info("got here");
let userQuery = new Moralis.Query(Moralis.User);
userQuery.equalTo("objectId", request.params.user_id);
logger.info("user id " + request.params.user_id);
userQuery.first({useMasterKey: true,
success: function (user) {
logger.info("got here 2");
user.set("fullName", "test");
user.save(null, { useMasterKey: true }).then((result) => {
// The object was saved successfully.
logger.info("success saving user");
}, (error) => {
// The save failed.
// error is a Moralis.Error with an error code and message.
logger.info("error saving user");
});
},
error: function (error) {
logger.info("error grabbing user");
},
});
});
if you comment this line, then it works?
instead of objectId can you try with id
?
this works fine for me:
Moralis.Cloud.define("TrackProgress", async (request) => {
logger.info("got here");
q = new Moralis.Query("User");
q.equalTo("objectId", "oDKz3DFG8Apj6gAxQmvkIsZU");
x = await q.find({useMasterKey:true})
logger.info(JSON.stringify(x))
return x
});
@cryptokid iāve gotten code to return back the found user before, but never been able to actually save any updates to that objectā¦
this updates the user object without problems:
Moralis.Cloud.define("TrackProgress", async (request) => {
logger.info("got here");
q = new Moralis.Query("User");
q.equalTo("objectId", "oDKz3DFG8Apj6gAxQmvkIsZU");
x = await q.find({useMasterKey:true})
logger.info(JSON.stringify(x))
x[0].set("username", "new_username")
x[0].save(null, {useMasterKey:true})
return x
});
@cryptokid the code still doesnāt seem to work, so weird!
this code:
// find user
let userQuery = new Moralis.Query(Moralis.User);
userQuery.equalTo("objectId", request.params.user_id);
results = await userQuery.find({useMasterKey:true});
logger.info(JSON.stringify(results));
// update user and save
results[0].set("username", "test");
results[0].save(null, {useMasterKey:true});
return results;
gives me this error:
Error: Invalid function: "TrackProgress"
at handleCloudFunction (/moralis-server/lib/Routers/FunctionsRouter.js:126:13)
at /moralis-server/lib/PromiseRouter.js:85:20
you can get that error if the code didnāt compile (because of an error somewhere) or the server was updating at that time
also make sure to use async in async (request)
@cryptokid ah that did it, it was the missing async in the method definition. Now i can save and update string values, but objects wonāt work and i cannot tell what to do from the docs. Iāve tried saving an object field in the database with both {} and ā{}ā
You can also search on google how to do something with parse server, most of the time it should be same syntax.