-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Link to reproduction
No response
Describe the Bug
We want to generate dev seed data from our production database. We need to remove sensitive data, so in prod we iterate through our collections and generate safe seed JSON files.
EG:
users.json
[
{
"_id": "6516875ee6d9097e0e0d6d35",
"name": "Foo",
"mfaKey": "",
"role": "admin",
"canTranslateLocales": [],
"email": "[email protected]",
"salt": "",
"hash": "",
"loginAttempts": 0,
"__v": 0,
"lockUntil": null
},
{
"_id": "6523b9b386ebc1443f5ec3c8",
"name": "Bar",
"mfaKey": "",
"role": "admin",
"canTranslateLocales": [],
"email": "[email protected]",
"salt": "",
"hash": "",
"loginAttempts": 0,
"__v": 0,
"lockUntil": null,
"resetPasswordExpiration": "2024-02-28T10:27:21.833Z",
"resetPasswordToken": ""
},
]In dev we run a migration that populates the DB with these files using mongo insertMany().
await payload.db.connection.collection('foo').insertMany(list)The problem is that we can't fetch models by their ID.
We can get data with payload.find(), and in the UI we can see the collection list view, but we get "Nothing Found" in the model view.
We can fetch models by ID using the mongo client:
// This works.
const mongoModel = await collection.findOne({_id: 'ABC123'})But not with payload:
// This doesn't work.
const payloadModel = await payload.findByID({
collection: 'foo',
id: 'ABC123',
})Our collections' schema are rather complex, which is why we want to generate dev seed data from prod. We need to maintain relationships between collections, so we need to populate the dev DB with IDs.
I would very much like to avoid creating an ID field on all collections just for this.
Are we missing a step?
To Reproduce
As above
Payload Version
2.19.3
Adapters and Plugins
"@payloadcms/bundler-webpack": "^1.0.6", "@payloadcms/db-mongodb": "^1.3.2", "@payloadcms/plugin-cloud-storage": "^1.1.1", "@payloadcms/plugin-sentry": "^0.0.6", "@payloadcms/richtext-slate": "^1.3.1",

