The开发者_StackOverflow社区 way I have my file structure set up right now is that I have a main folder calles users. In that folder we have a document with a randomly generated name that contain some information along with another folder for files. I would like to duplicate this only using code. I could either run a function to build a template from scratch, or build a function to duplicate a file along with its subfolders. Fyi, the file tree goes as such - [users] -> [user_document/user_information] -> [images]
I have yet to find any resources about this online, or maybe I'm not looking in the right areas, either ways, thanks for your help.
To add a new document to a collection, use the add method on a CollectionReference:
import firestore from '@react-native-firebase/firestore';
firestore()
.collection('Users')
.add({
image: "https://images.pexels.com/photos/10640445/pexels-photo-10640445.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",
})
.then(() => {
console.log('User added!');
});
The add method adds the new document to your collection with a random unique ID. If you'd like to specify your own ID, call the set method on a DocumentReference instead:
import firestore from '@react-native-firebase/firestore';
firestore()
.collection('Users')
.doc('ABC')
.set({
image: "https://images.pexels.com/photos/10640445/pexels-photo-10640445.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",
})
.then(() => {
console.log('User added!');
});
For more details refer to the docs
Hope this helps. Happy Coding :)
精彩评论