Bulk Upload JSON Data to Cloud Firestore Collections | Quick Firebase Tutorial

preview_player
Показать описание
#firebase #firestore #bulkupload
In this Quick Firebase Tutorial, we will be talking a look at a script to upload bulk JSON data to Your Cloud Firestore collections. This is an easy and convenient way to upload large amount of data to cloud firestore / firebase which otherwise would be hard to upload manually.

👉 🔥STOP!! You can now use "FireKit" for all this and even more...! NO CODE REQUIRED! 🔥
✔ Upload & Download Bulk data from Firestore Collections
✔ Full Support for Nested Collections
✔ Instant Upload and much more...

Download Project Files (Drive):

We will be running the script using node which you can download via the link below:

Social Links:

If you find this tutorial helpful, please hit the LIKE and SUBSCRIBE button for more Development Tutorials.

Happy Coding..
Рекомендации по теме
Комментарии
Автор

For anyone having issues installing the firebase and firebase-admin packages you can run the following commands to update them to the latest version:
1. npm install -g npm-check-updates
2. npm-check-updates -u
3. npm install

Thanks for the great video btw, and very cool that you launched FireKit!
Tom

tomnewton
Автор

Thank you! You can delete the databaseURL line, no need to include in latest version.

If you're getting an error: 'Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string.' it's because you need to either include "ItemID": "<desired doc name>" in each object or you can update lines 27 & 28 to the below to have firebase auto-generate the id for you.

.doc()
.create(obj)

bingerminn
Автор

Thanks for the solution. Very useful to me too...

I also made a Readme file for some error encountered( STEP 3 mainly) :

This project is for uploading json files to Firebase's Coud Firestore database.


1. Add all your .json files to the files folder

2. open terminal and run : npm install firebase firebase-admin

3. Update the part : doc(obj.itemID) to .doc(obj.itemID || obj.<YOUR_DOCUMENT_IDS) i.e Update this section to match the ID of documents within your collection, The ID will be used to create individual documents within your collection

4. open terminal and run : node uploader.js


NB: this script assumes your collections to be uploaded are not nested.
==

johnsondlamini
Автор

Great stuff! This is really helpful. I read an article on this subject on "medium", but it was only half of the info needed. Thanx for this.

Автор

So glad I found this before I started coding a solution on my own lol. Thanks!

HP
Автор

my one didn't work at first but i got it working, it really depends on what type of json file that you're working with my one had object but I modified it a little bit and the main uploader.js file code and wala it worked like a charm! Here's a tip below :
menu.forEach(function (obj) {
firestore
.collection('myCollection') // this is the main collection name
.doc() // if you want auto id keep it like this (empty)
.set(obj)
.then(function (docRef) {
console.log("Document written");
})
.catch(function (error) {
console.error("Error adding document: ", error);
});
});




this code won't work if you don't have an array because " menu.forEach(function (obj) { " is an array fucntion which will work only on arrays
Best of luck !

imransefat
Автор

Thanks for posting this helpful. FYI for people > code has some assumptions like you aren't storing any other directories or non json files within the "files" directory.

kylekastilahn
Автор

There's no database URL on firestore. Where can I find it?

marcusshamase
Автор

Thanks a lot for your work. It has sped up my project by leaps and bounds

amdfamdf
Автор

Made my life whole lot easier. Thanks (Liked and subbed so keep it coming)

bataabagi
Автор

Awesome. Just used it, and had to make changes there and there docID and it worked like a charm!

mellojmmebe
Автор

This is a great video! Thanks so much. Would love to see more stuff like this! Great work!

finalbossediting
Автор

Great tutorial, a life saver for me. One day I will try to write something like your script in Dart.

stefaandeconinck
Автор

If you want to get the document ID before it was added:

menu.forEach(function(obj) {
var newDocRef =
obj.itemId= newDocRef.id;
newDocRef.set(obj)
.then(function(docRef) {
console.log("Document written");
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
});

Goodluck and you're doing great.

Rafael-hkpg
Автор

Why I can't upload just single json file? It worked with your files, so I tried with one mine and it didn't work, I've got error

adamheinrich
Автор

This works up to a certain amount of data before you hit the quota.
Good job though !

tntg
Автор

If you find this video useful, consider Following me on:
Happy Coding! ✌️😁

RetroPortalStudio
Автор

One of the most useful video. Thanks mate for helping me out

jeevancrasta
Автор

a very clear explanation. Congratulations.

gustavobejarano
Автор

Thank's a lot, you really help me!

Oru_Han