根据ID更新分析数据库中的行

Updating a row in Parse database against an ID

本文关键字:数据库 ID 更新 根据      更新时间:2023-09-26

我正在尝试使用java脚本针对特定的userId(parse数据库中表中的列)更新解析数据库中的一行。然而问题是,当下面的代码运行时,会创建一个新行。我不知道自己做错了什么。

var profileQuery = new Parse.Query(Profile);
                            profileQuery.equalTo("userId","objectId")
                            profileQuery.first({
                              success: function(object) 
                                {
                                    profile.set("profilePic", theFile);
                                    profile.save({success: function()
                                    {
                                        console.log("Profile Picture saved successfully !");
                                        profileQuery.find({
                                            success: function(results)
                                            {
                                                var output ="";
                                                for (var i in results) 
                                                {
                                                    if(results[i].get("profilePic")) 
                                                    {
                                                        var file = results[i].get("profilePic");
                                                        var url = file.url();
                                                        console.log("Image URL is:"+url);
                                                        console.log(" Value of i: "+i);
                                                        document.getElementById("profileDp").src=url;
                                                    }
                                                }
                                            }
                                            });
                                            }, error: function(file, error){
                                                console.log("Profile pic upload error !" + error.message);
                                            }
                                        });
                                },
                              error: function(error) {
                                alert("Error: " + error.code + " " + error.message);
                              }
                            }); 

有什么想法吗?

解决了它!万一有人好奇,下面是修改后的代码:

var profileQuery = new Parse.Query(Profile);
                                profileQuery.equalTo("userId",objectId);
                                profileQuery.first({
                                  success: function(object) 
                                    {
                                        object.set("profilePic", theFile);
                                        object.save({success: function()
                                        {
                                            console.log("Profile Picture saved successfully !");
                                            profileQuery.find({
                                                success: function(results)
                                                {
                                                    var output ="";
                                                    for (var i in results) 
                                                    {
                                                        if(results[i].get("profilePic")) 
                                                        {
                                                            var file = results[i].get("profilePic");
                                                            var url = file.url();
                                                            console.log("Image URL is:"+url);
                                                            console.log(" Value of i: "+i);
                                                            document.getElementById("profileDp").src=url;
                                                        }
                                                    }
                                                }
                                                });
                                                }, error: function(file, error){
                                                    console.log("Profile pic upload error !" + error.message);
                                                }
                                            });
                                    },
                                  error: function(error) {
                                    alert("Error: " + error.code + " " + error.message);
                                  }
                                });