🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Discussion about exporting/importing documents between dev and production servers using Sanity.io

29 replies
Last updated: Jul 20, 2022
is there a quick an dirty way to export a document from a dev server to import to a production server?
Jul 12, 2022, 2:54 PM
do you mean a specific doc (data only) or a schema?
Jul 12, 2022, 2:58 PM
a specific doc
Jul 12, 2022, 3:05 PM
like i have a document with quite a bit of data entered
Jul 12, 2022, 3:05 PM
and i don't reaaallly want to copy it over manually
Jul 12, 2022, 3:05 PM
check your production 😉 BUT
sanity deploy
Jul 12, 2022, 3:06 PM
just hoping for a
sanity dataset export --doc-id {some-doc-id}
or something like that, so i can then
sanity dataset import --missing
Jul 12, 2022, 3:07 PM
not sure what you mean?...
i've got spaces setup, so i have a
dataset and
dataset deployed
and i want to copy over a document from staging -> prod
Jul 12, 2022, 3:08 PM
So wait 2 different datasets or did you setup a schema in your code and filled it with data on localhost:3333?Or do you have 2 datasets?
Jul 12, 2022, 3:10 PM
i have two datasets right now:
. and it has been deployed with
sanity deploy
we have a new document on staging that i want to copy over.
Jul 12, 2022, 3:14 PM
that being said, i do still think there is a bit of confusion on my end on the best way to setup a dev -> staging -> prod environment and have it as smooth as possible for devs and content writers.

i've asked it plenty of times here and feel like everybody has a different solution that they implement or recommend

at the moment, using previous advice. we have our "live" project with two datasets:
. with spaces setup so we have a quick switcher on

the content writers add content there.

as for devs (like me) we have our own projects setup and anytime we work on new stuff we export the production dataset and import to the local/personal project: we make changes (ie updating schema, adding/testing with local content)

then when we want to push up to staging i deploy the schema changes to the "live" project. and the content team will create the new page on staging. and here we are ready to push to live, and i want to know if i can just export/import that new document
Jul 12, 2022, 3:27 PM
it seems like there might be "better" way but i haven't been able to wrap my head around it to make it work for our team
Jul 12, 2022, 3:28 PM
Okay crystal clear now :minecraft-diamond: I will investigate for you about the import/export! I just did not understand your question 🙈 but you are doing the right thing especially if you have bigger teams working on all sides. Safety first ☝️If you need some pointers I could try and find a best practice for you, if you share more details about your needs in general
Jul 12, 2022, 6:14 PM
ok that'd be great. I will try to write out all the details when i have a few mins
Jul 13, 2022, 3:52 PM
we just made some schema changes. tested them locally on a project with a different id than the live studio. all good
now i want to launch to staging to test it out.

we have spaces setup in our studio to be able to switch between

i ran
sanity deploy
with these in my

which deploy the desk structure change to BOTH datasets

when the result i wanted was just on the staging dataset 😞
Jul 18, 2022, 6:55 PM
user J
Jul 18, 2022, 6:57 PM
user T
to the rescue: https://github.com/sanity-io/cross-dataset-duplicator
“This plugin is designed as a convenience for Authors to make small, infrequent content migrations between Datasets.”
user E
for this find
Jul 18, 2022, 7:21 PM
so i think this is a great solution, buuuut
user T
could you help me diagnose some issues?
seems like the duplicate from isn't getting populated...
Jul 19, 2022, 5:18 PM
missing projectId... is there a way to set it in .env.development somehow? cuz i don't want to commit the projectId to
Jul 19, 2022, 5:18 PM
The plug-in will require it to be loaded in sanity.json
If your dataset is set to private, there's no risk to leaking data from a projectId alone.
Jul 19, 2022, 5:22 PM
hmm k. thanks for the help.
is there any technical reason that the projectID can't be loaded elsewhere? could i make an issue on github for that?
Jul 19, 2022, 5:43 PM
Just the way the plug-in is configured, it relies on the Spaces config.
Feel free to write up an issue for it :)
Jul 19, 2022, 5:46 PM
🤔 i wonder how/why spaces is working fine for me without the projectID... it must be grabbing it from somewhere... likely the .env file
Jul 19, 2022, 5:49 PM
Mmm… maybe there's more I can look at. Write an issue and I'll follow it up.
Jul 19, 2022, 5:50 PM
already on it
Jul 19, 2022, 5:51 PM
lemme know if you need more info/help with the fix
Jul 19, 2022, 5:59 PM
not sure if there is a better spot to chat about this: but i would be interested in contributing to this plugin. is there any special considerations? or just make issues, discussions and PRs?
Jul 19, 2022, 6:06 PM
Would love a PR 😊
I usually use “npm link” to work with plugins in the studio. Let me know if you need more details.
Jul 20, 2022, 5:19 AM
user T
if you have some docs or something for plugin development best practices please let me know. I'm not familiar with
npm link
, i come from php background.
So any tips on the best dev workflow would be great. cheers
Jul 20, 2022, 8:48 PM
There's a guide here in the plug-in starter it's based on
Jul 20, 2022, 8:55 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?