如何使用Node JS在Parse中插入记录?

时间:2019-02-19 05:32:28

标签: node.js post parse-platform parse-server

我正在尝试使用Node JS作为服务器端实现并使用Parse-API来管理NoSQL数据库来实现CRUD功能。这是实现该代码的代码。 get()工作正常,但post()方法工作异常。还有一件事,是否可以应用层叠删除,使用Parse更新?如何在关联表中插入记录,例如当我为产品创建记录时,数据将被插入两个表中。

Get()正在工作。

var express = require('express');
app = express();
Parse = require('parse/node');
var AppID = "XXXXXX";
var Masterkey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var serverURL = "http://myserverIP:port/parse";
Parse.initialize(AppID, Masterkey);
Parse.serverURL = serverURL;
var server = app.listen(9000, '127.0.0.1', function (req, res) {
    var host = server.address().address
    var port = server.address().port
    console.log(`Server running at http://${host}:${port}/`);
});
app.get('/getTest', function (req, res) {
    GetRecord();
});
app.post('/postTest', function (req, res) {
    PostRecord();
    PostRecord1(); //also tried
});
async function GetRecord() {
    const test = Parse.Object.extend("test");
    const query = new Parse.Query(test);
    const results = await query.find();
    console.log("Successfully retrieved " + results.length + " test.");
    for (let i = 0; i < results.length; i++) {
        var object = results[i];
        console.log(object.id + ' - ' + object.get('name'));
    }
}
function PostRecord() {
    var Test = new Parse.Object.extend("test");
    test.set("name", "Hiren Patel");
    test.save()
        .then((test) => {
            alert('New object created with objectId: ' + test.id);
        }, (error) => {
            alert('Failed to create new object, with error code: ' + error.message);
        });
}
function PostRecord1() {
    var Test = Parse.Object.extend("test");
    var test = new Test();
    test.set("name", "Hiren Patel");
    test.save();
}

0 个答案:

没有答案