Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save badboy-tian/3bb44139d2346f159fd4cd9e5cf5aecb to your computer and use it in GitHub Desktop.
Save badboy-tian/3bb44139d2346f159fd4cd9e5cf5aecb to your computer and use it in GitHub Desktop.
ParseError: Object not found
const Parse = require("parse/node")
const moment = require("moment")
Parse.initialize("debug_appid", "debug_key", "debug_masterKey")
Parse.serverURL = "http://localhost:1337/parse"
const body = {
name: "SaveAudio",
data: "{\"__after\":\"1716788669509,2cf6e3698932972402fa3ca2405b437dc3ac727a\",\"isDeleted\":false,\"name\":\"好的呢,宝宝\",\"duration\":2,\"url\":\"http://file2.xxxx.com/FdD9KwF4xNgBHTiGcJByMNs6P470XNFp/20240405195209.mp3\",\"user\":{\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"65de1d08caa7af401d105a56\"},\"pack\":{\"__type\":\"Pointer\",\"className\":\"SaveAudioPack\",\"objectId\":\"65e9fcec4567a26864d47d2b\"},\"objectId\":\"66541dbdffead844f1339e3c\",\"createdAt\":\"2024-05-27T05:44:29.504Z\",\"updatedAt\":\"2024-05-27T05:44:29.504Z\"}"
};
async function test() {
const name = body.name;
const data = JSON.parse(body.data);
const testObject = new Parse.Object(name);
testObject.id = data.objectId;
const entries = Object.entries(data);
const map = [];
for (let i = 0; i < entries.length; i++) {
map.push({
key: entries[i][0],
value: entries[i][1]
})
}
for (let i = 0; i < map.length; i++) {
const key = map[i].key;
const value = map[i].value;
if (key === "__after") {
continue;
}
if (key === "createdAt" || key === "updatedAt") {
testObject.set(key, moment(value).toDate());
continue;
}
//处理Pointer
if (typeof value === "object" && value.__type === "Pointer") {
let className = value.className;
if (className === "_File") {
className = "AVFile";
}
const InnerObject = Parse.Object.extend(className);
testObject.set(key, InnerObject.createWithoutData(value.objectId))
} else {
testObject.set(key, value);
}
}
console.log(testObject.toJSON())
await testObject.save(null, {useMasterKey: true});
}
test();
@badboy-tian
Copy link
Author

PS D:\web\import> node .\dist\testCustomObjectId.js
{
  isDeleted: false,
  name: '好的呢,宝宝',
  duration: 2,
  url: 'http://file2.xxx.com/FdD9KwF4xNgBHTiGcJByMNs6P470XNFp/20240405195209.mp3',
  user: {
    __type: 'Pointer',
    className: '_User',
    objectId: '65de1d08caa7af401d105a56'
  },
  pack: {
    __type: 'Pointer',
    className: 'SaveAudioPack',
    objectId: '65e9fcec4567a26864d47d2b'
  },
  objectId: '66541dbdffead844f1339e3c'
}
D:\web\import\node_modules\parse\lib\node\RESTController.js:298
        error = new _ParseError.default(errorJSON.code, errorJSON.error);
                ^

ParseError: Object not found.
    at handleError (D:\web\import\node_modules\parse\lib\node\RESTController.js:298:17)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment