Closed ericnation closed 8 years ago
HI,do you resolve it?
Its been so long I actually can't remember how I resolved it. Sorry.
@wuzhouyang In case you have the same issue, one of the possible reasons can be that in db.json
you have an array with no id
.
For example, this will fail:
{ "posts": [ { "title": "..." } ] }
But this will work:
{ "posts": [ { "id": 1, "title": "..." } ] }
You might want to explicitly state the id requirement for db.json to the documentation. I had the same issue, it was quite difficult to debug without knowing that the db had to be formatted a specific way.
Why force id
field?
simple solution. to this is adding "id" to your JSON object. I just did that and it is working fine.
what if you just pass --id or -i to switch id to another key field
JSON data needs a property named "id" to store the data we send.(If already some data is stored manually in the DB. So if you already have data in your json file please make sure that u add "id" property to it. e.g. "data": [ { "id": "1", "name" : "Andy",
I get this error when making a post or put request. I'm using anguar-cli in my project.
Cannot read property 'id' of undefined
at Function.createId (/<mypath>/web-projects/ngrx-checkout/node_modules/json-server/src/server/mixins.js:46:7) at Function.module.exports.insert (/<mypath>/web-projects/ngrx-checkout/node_modules/underscore-db/src/index.js:58:31) at /<mypath>/web-projects/ngrx-checkout/node_modules/lodash/lodash.js:3899:28 at arrayReduce (/<mypath>/web-projects/ngrx-checkout/node_modules/lodash/lodash.js:618:21) at baseWrapperValue (/<mypath>/web-projects/ngrx-checkout/node_modules/lodash/lodash.js:3898:14) at LodashWrapper.wrapperValue (/<mypath>/web-projects/ngrx-checkout/node_modules/lodash/lodash.js:8345:14) at LodashWrapper.<anonymous> (/<mypath>/web-projects/ngrx-checkout/node_modules/lowdb/lib/_index.js:77:19) at apply (/<mypath>/web-projects/ngrx-checkout/node_modules/lodash/lodash.js:409:27) at LodashWrapper.wrapper [as value] (/<mypath>/web-projects/ngrx-checkout/node_modules/lodash/lodash.js:4837:16) at create (/<mypath>/web-projects/ngrx-checkout/node_modules/json-server/src/server/router/plural.js:210:8)