Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var prevPost = new Post();
- console.log("#0 " + prevPost._id);
- Object.assign(prevPost, post);
- //prevPost._id = undefined; // 새로운 아이디를 부여받기 위해 기존 _id 제거
- console.log("#1 " + prevPost._id);
- prevPost._id = undefined;
- console.log("#2 " + prevPost._id);
- prevPost.origin = post.key;
- prevPost.key = shortid.generate(),
- prevPost.save().then(output => {
- console.log("# prevPost is saved");
- console.log(output);
- })
- /* 오류메세지
- received data = {
- "key": "BkKc1Ct-m",
- "title": "33",
- "writer": "mac.chrome",
- "content": "33ffvf",
- "date": 1529632023387,
- "isPrivate": false,
- "hasComment": true,
- "viewCnt": 2,
- "uuid": "HyIL0vO-7"
- }
- #0 5b2c55174b45901a42dec8ed
- #1 5b2c4f91fa8a1712ad68cefc
- #2 5b2c55174b45901a42dec8ee
- ## 1111
- ## 2222
- { ParallelSaveError: Can't save() the same doc multiple times in parallel. Document: 5b2c55174b45901a42dec8ee
- at ParallelSaveError.MongooseError [as constructor] (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/error/index.js:12:11)
- at new ParallelSaveError (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/error/parallelSave.js:18:17)
- at model.Model.save (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/model.js:337:23)
- at Post.findOne.then.post (/Users/songmingu/Documents/project/talkplace/server/postRouter.js:68:22)
- at <anonymous>
- at process._tickCallback (internal/process/next_tick.js:188:7)
- message: 'Can\'t save() the same doc multiple times in parallel. Document: 5b2c55174b45901a42dec8ee',
- name: 'ParallelSaveError' }
- */
- console.log("#0 " + JSON.stringify(post, null, 2));
- let tmp = Object.assign({}, post);
- tmp._id = undefined;
- console.log("#1 " + JSON.stringify(tmp, null, 2));
- var prevPost = new Post();
- console.log("#2 " + JSON.stringify(prevPost, null, 2));
- Object.assign(prevPost, tmp);
- console.log("#3 " + JSON.stringify(prevPost, null, 2));
- /*
- received data = {
- "key": "BkKc1Ct-m",
- "title": "33",
- "writer": "mac.chrome",
- "content": "33ffvf",
- "date": 1529632436198,
- "isPrivate": false,
- "hasComment": true,
- "viewCnt": 2,
- "uuid": "HyIL0vO-7"
- }
- #0 {
- "_id": "5b2c4f91fa8a1712ad68cefc",
- "key": "BkKc1Ct-m",
- "title": "33",
- "writer": "mac.chrome",
- "content": "66",
- "date": 1529631000544,
- "isPrivate": false,
- "hasComment": true,
- "uuid": "HyIL0vO-7",
- "commentCnt": 0,
- "__v": 0,
- "viewCnt": 2,
- "origin": "BkKc1Ct-m"
- }
- #1 {
- "$__": {
- "strictMode": true,
- "selected": {},
- "getters": {},
- "_id": "5b2c4f91fa8a1712ad68cefc",
- "wasPopulated": false,
- "activePaths": {
- "paths": {
- "_id": "init",
- "key": "init",
- "title": "init",
- "writer": "init",
- "content": "init",
- "date": "init",
- "isPrivate": "init",
- "hasComment": "init",
- "uuid": "init",
- "commentCnt": "init",
- "__v": "init",
- "viewCnt": "init",
- "origin": "init"
- },
- "states": {
- "ignore": {},
- "default": {},
- "init": {
- "_id": true,
- "key": true,
- "title": true,
- "writer": true,
- "content": true,
- "date": true,
- "isPrivate": true,
- "hasComment": true,
- "uuid": true,
- "commentCnt": true,
- "__v": true,
- "viewCnt": true,
- "origin": true
- },
- "modify": {},
- "require": {}
- },
- "stateNames": [
- "require",
- "modify",
- "init",
- "default",
- "ignore"
- ]
- },
- "pathsToScopes": {},
- "emitter": {
- "domain": null,
- "_events": {},
- "_eventsCount": 0,
- "_maxListeners": 0
- },
- "$options": {
- "skipId": true,
- "isNew": false,
- "skipDefaults": {
- "_id": true,
- "key": true,
- "title": true,
- "writer": true,
- "content": true,
- "date": true,
- "isPrivate": true,
- "hasComment": true,
- "uuid": true,
- "commentCnt": true,
- "__v": true,
- "viewCnt": true,
- "origin": true
- }
- }
- },
- "isNew": false,
- "_doc": {
- "_id": "5b2c4f91fa8a1712ad68cefc",
- "key": "BkKc1Ct-m",
- "title": "33",
- "writer": "mac.chrome",
- "content": "66",
- "date": 1529631000544,
- "isPrivate": false,
- "hasComment": true,
- "uuid": "HyIL0vO-7",
- "commentCnt": 0,
- "__v": 0,
- "viewCnt": 2,
- "origin": "BkKc1Ct-m"
- },
- "$init": true
- }
- #2 {
- "_id": "5b2c56b47e127a1b2e8f6acb"
- }
- #3 {
- "_id": "5b2c56b47e127a1b2e8f6acc",
- "key": "BkKc1Ct-m",
- "title": "33",
- "writer": "mac.chrome",
- "content": "66",
- "date": 1529631000544,
- "isPrivate": false,
- "hasComment": true,
- "uuid": "HyIL0vO-7",
- "commentCnt": 0,
- "__v": 0,
- "viewCnt": 2,
- "origin": "BkKc1Ct-m"
- }
- ## 1111
- ## 2222
- { ParallelSaveError: Can't save() the same doc multiple times in parallel. Document: 5b2c56b47e127a1b2e8f6acc
- at ParallelSaveError.MongooseError [as constructor] (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/error/index.js:12:11)
- at new ParallelSaveError (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/error/parallelSave.js:18:17)
- at model.Model.save (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/model.js:337:23)
- at Post.findOne.then.post (/Users/songmingu/Documents/project/talkplace/server/postRouter.js:69:22)
- at <anonymous>
- at process._tickCallback (internal/process/next_tick.js:188:7)
- message: 'Can\'t save() the same doc multiple times in parallel. Document: 5b2c56b47e127a1b2e8f6acc',
- name: 'ParallelSaveError' }
- */
Add Comment
Please, Sign In to add comment