Guest User

Untitled

a guest
Jun 23rd, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. var prevPost = new Post();
  2. console.log("#0 " + prevPost._id);
  3. Object.assign(prevPost, post);
  4. //prevPost._id = undefined; // 새로운 아이디를 부여받기 위해 기존 _id 제거
  5. console.log("#1 " + prevPost._id);
  6. prevPost._id = undefined;
  7. console.log("#2 " + prevPost._id);
  8.  
  9. prevPost.origin = post.key;
  10. prevPost.key = shortid.generate(),
  11.  
  12. prevPost.save().then(output => {
  13. console.log("# prevPost is saved");
  14. console.log(output);
  15. })
  16.  
  17.  
  18. /* 오류메세지
  19. received data = {
  20. "key": "BkKc1Ct-m",
  21. "title": "33",
  22. "writer": "mac.chrome",
  23. "content": "33ffvf",
  24. "date": 1529632023387,
  25. "isPrivate": false,
  26. "hasComment": true,
  27. "viewCnt": 2,
  28. "uuid": "HyIL0vO-7"
  29. }
  30. #0 5b2c55174b45901a42dec8ed
  31. #1 5b2c4f91fa8a1712ad68cefc
  32. #2 5b2c55174b45901a42dec8ee
  33. ## 1111
  34. ## 2222
  35. { ParallelSaveError: Can't save() the same doc multiple times in parallel. Document: 5b2c55174b45901a42dec8ee
  36. at ParallelSaveError.MongooseError [as constructor] (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/error/index.js:12:11)
  37. at new ParallelSaveError (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/error/parallelSave.js:18:17)
  38. at model.Model.save (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/model.js:337:23)
  39. at Post.findOne.then.post (/Users/songmingu/Documents/project/talkplace/server/postRouter.js:68:22)
  40. at <anonymous>
  41. at process._tickCallback (internal/process/next_tick.js:188:7)
  42. message: 'Can\'t save() the same doc multiple times in parallel. Document: 5b2c55174b45901a42dec8ee',
  43. name: 'ParallelSaveError' }
  44.  
  45. */
  46.  
  47.  
  48.  
  49. console.log("#0 " + JSON.stringify(post, null, 2));
  50. let tmp = Object.assign({}, post);
  51. tmp._id = undefined;
  52. console.log("#1 " + JSON.stringify(tmp, null, 2));
  53. var prevPost = new Post();
  54. console.log("#2 " + JSON.stringify(prevPost, null, 2));
  55. Object.assign(prevPost, tmp);
  56. console.log("#3 " + JSON.stringify(prevPost, null, 2));
  57.  
  58. /*
  59. received data = {
  60. "key": "BkKc1Ct-m",
  61. "title": "33",
  62. "writer": "mac.chrome",
  63. "content": "33ffvf",
  64. "date": 1529632436198,
  65. "isPrivate": false,
  66. "hasComment": true,
  67. "viewCnt": 2,
  68. "uuid": "HyIL0vO-7"
  69. }
  70. #0 {
  71. "_id": "5b2c4f91fa8a1712ad68cefc",
  72. "key": "BkKc1Ct-m",
  73. "title": "33",
  74. "writer": "mac.chrome",
  75. "content": "66",
  76. "date": 1529631000544,
  77. "isPrivate": false,
  78. "hasComment": true,
  79. "uuid": "HyIL0vO-7",
  80. "commentCnt": 0,
  81. "__v": 0,
  82. "viewCnt": 2,
  83. "origin": "BkKc1Ct-m"
  84. }
  85. #1 {
  86. "$__": {
  87. "strictMode": true,
  88. "selected": {},
  89. "getters": {},
  90. "_id": "5b2c4f91fa8a1712ad68cefc",
  91. "wasPopulated": false,
  92. "activePaths": {
  93. "paths": {
  94. "_id": "init",
  95. "key": "init",
  96. "title": "init",
  97. "writer": "init",
  98. "content": "init",
  99. "date": "init",
  100. "isPrivate": "init",
  101. "hasComment": "init",
  102. "uuid": "init",
  103. "commentCnt": "init",
  104. "__v": "init",
  105. "viewCnt": "init",
  106. "origin": "init"
  107. },
  108. "states": {
  109. "ignore": {},
  110. "default": {},
  111. "init": {
  112. "_id": true,
  113. "key": true,
  114. "title": true,
  115. "writer": true,
  116. "content": true,
  117. "date": true,
  118. "isPrivate": true,
  119. "hasComment": true,
  120. "uuid": true,
  121. "commentCnt": true,
  122. "__v": true,
  123. "viewCnt": true,
  124. "origin": true
  125. },
  126. "modify": {},
  127. "require": {}
  128. },
  129. "stateNames": [
  130. "require",
  131. "modify",
  132. "init",
  133. "default",
  134. "ignore"
  135. ]
  136. },
  137. "pathsToScopes": {},
  138. "emitter": {
  139. "domain": null,
  140. "_events": {},
  141. "_eventsCount": 0,
  142. "_maxListeners": 0
  143. },
  144. "$options": {
  145. "skipId": true,
  146. "isNew": false,
  147. "skipDefaults": {
  148. "_id": true,
  149. "key": true,
  150. "title": true,
  151. "writer": true,
  152. "content": true,
  153. "date": true,
  154. "isPrivate": true,
  155. "hasComment": true,
  156. "uuid": true,
  157. "commentCnt": true,
  158. "__v": true,
  159. "viewCnt": true,
  160. "origin": true
  161. }
  162. }
  163. },
  164. "isNew": false,
  165. "_doc": {
  166. "_id": "5b2c4f91fa8a1712ad68cefc",
  167. "key": "BkKc1Ct-m",
  168. "title": "33",
  169. "writer": "mac.chrome",
  170. "content": "66",
  171. "date": 1529631000544,
  172. "isPrivate": false,
  173. "hasComment": true,
  174. "uuid": "HyIL0vO-7",
  175. "commentCnt": 0,
  176. "__v": 0,
  177. "viewCnt": 2,
  178. "origin": "BkKc1Ct-m"
  179. },
  180. "$init": true
  181. }
  182. #2 {
  183. "_id": "5b2c56b47e127a1b2e8f6acb"
  184. }
  185. #3 {
  186. "_id": "5b2c56b47e127a1b2e8f6acc",
  187. "key": "BkKc1Ct-m",
  188. "title": "33",
  189. "writer": "mac.chrome",
  190. "content": "66",
  191. "date": 1529631000544,
  192. "isPrivate": false,
  193. "hasComment": true,
  194. "uuid": "HyIL0vO-7",
  195. "commentCnt": 0,
  196. "__v": 0,
  197. "viewCnt": 2,
  198. "origin": "BkKc1Ct-m"
  199. }
  200. ## 1111
  201. ## 2222
  202. { ParallelSaveError: Can't save() the same doc multiple times in parallel. Document: 5b2c56b47e127a1b2e8f6acc
  203. at ParallelSaveError.MongooseError [as constructor] (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/error/index.js:12:11)
  204. at new ParallelSaveError (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/error/parallelSave.js:18:17)
  205. at model.Model.save (/Users/songmingu/Documents/project/talkplace/node_modules/mongoose/lib/model.js:337:23)
  206. at Post.findOne.then.post (/Users/songmingu/Documents/project/talkplace/server/postRouter.js:69:22)
  207. at <anonymous>
  208. at process._tickCallback (internal/process/next_tick.js:188:7)
  209. message: 'Can\'t save() the same doc multiple times in parallel. Document: 5b2c56b47e127a1b2e8f6acc',
  210. name: 'ParallelSaveError' }
  211. */
Add Comment
Please, Sign In to add comment