Populating Material-UI DataGrid from MongoDB failing for unique ID not found Populating Material-UI DataGrid from MongoDB failing for unique ID not found mongodb mongodb

Populating Material-UI DataGrid from MongoDB failing for unique ID not found


You can now use the getRowId property that accepts a function to specify which property on each row should be considered the id.

In the OP's case, you could do: getRowId={(row) => row._id}

Reference: https://github.com/mui-org/material-ui-x/pull/972


I just put the option { virtuals: true } in my schema:

const opts = { toJSON: { virtuals: true } };const schema = new mongoose.Schema({    lastName: String,    firstName: String,    nickname: String,}, opts);

So when i try to query, the field "id" is added. Something like:

[{"_id": "602fc7aba323ec87f00f9c76","lastName": "Targaryen","firstName": "Daenerys","nickname": "","__v": 0,"id": "602fc7aba323ec87f00f9c76"}]


I was having a hard time with this too, turns out you can make virtual ids

https://mongoosejs.com/docs/tutorials/virtuals.html