- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在下面有一个名为 seed.js 代码的文件,我想将其数据从我的 React js 应用程序添加到 Firebase Firestore。有没有可以让我这样做的脚本?
我想如果我解开
import { seedDatabase } from './seed';
对于 index.js 文件,它将运行文件并将数据添加到 firebase?
下面是我的seed.js文件代码
export function seedDatabase(firebase) {
function getUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const piece = (Math.random() * 16) | 0;
const elem = c === 'x' ? piece : (piece & 0x3) | 0x8;
return elem.toString(16);
});
}
/* Series
============================================ */
// Documentaries
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Tiger King',
description: 'An exploration of big cat breeding and its bizarre underworld, populated by eccentric characters.',
genre: 'documentaries',
maturity: '18',
slug: 'tiger-king',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Amanda Knox',
description: 'Amanda Marie Knox is an American woman who spent almost four years in an Italian prison.',
genre: 'documentaries',
maturity: '12',
slug: 'amanda-knox',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Citizenfour',
description:
'Citizenfour is a 2014 documentary film directed by Laura Poitras, concerning Edward Snowden and the NSA spying scandal.',
genre: 'documentaries',
maturity: '12',
slug: 'citizenfour',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Super Size Me',
description:
"Director Morgan Spurlock's social experiment in fast-food gastronomy sees him attempting to subsist uniquely on food from the McDonalds",
genre: 'documentaries',
maturity: '12',
slug: 'super-size-me',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Man on Wire',
description:
"Filmmaker James Marsh masterfully recreates high-wire daredevil Philippe Petit's 1974 stunt walking on a wire across the Twin Towers.",
genre: 'documentaries',
maturity: '12',
slug: 'man-on-wire',
});
// Comedies
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'The Office',
description:
'A motley group of office workers go through hilarious misadventures at the Scranton, Pennsylvania, branch of the Dunder Mifflin Paper Company.',
genre: 'comedies',
maturity: '15',
slug: 'the-office',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Arrested Development',
description:
'The Bluth family, once a prominent name in the business, loses everything after the head patriarch gets convicted for fraud.',
genre: 'comedies',
maturity: '15',
slug: 'arrested-development',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Curb Your Enthusiasm',
description:
'Larry David, a famous television writer and producer, gets into various misadventures with his friends and celebrity colleagues in Los Angeles.',
genre: 'comedies',
maturity: '15',
slug: 'curb-your-enthusiasm',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Family Guy',
description:
'Peter Griffin and his family of two teenagers, a smart dog, a devilish baby and his wife find themselves in some of the most hilarious scenarios.',
genre: 'comedies',
maturity: '15',
slug: 'family-guy',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'South Park',
description:
'Four young, schoolgoing boys, Stan Marsh, Kyle Broflovski, Eric Cartman and Kenny McCormick, who live in South Park set out on various adventures.',
genre: 'comedies',
maturity: '15',
slug: 'south-park',
});
// Children
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Peppa Pig',
description:
'Peppa, an outgoing preschool pig, participates in many energetic activities. She learns something new every day and has a lot of fun with her family and friends.',
genre: 'children',
maturity: '0',
slug: 'peppa-pig',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Dora The Explorer',
description:
'Dora, a seven-year-old girl of Latin American descent, embarks upon numerous adventures in the wilderness with her friend Boots, a monkey, and a variety of fun and useful tools.',
genre: 'children',
maturity: '0',
slug: 'dora-the-explorer',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'PAW Patrol',
description:
'Six brave puppies, captained by a tech-savvy ten-year-old boy, Ryder, work together to accomplish high-stakes rescue missions to safeguard the residents of the Adventure Bay community.',
genre: 'children',
maturity: '0',
slug: 'paw-patrol',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Arthur',
description:
'Bespectacled aardvark Arthur Read demonstrates to kids how to deal with such childhood traumas and challenges as homework, teachers and bullies.',
genre: 'children',
maturity: '0',
slug: 'arthur',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'SpongeBob',
description:
'A yellow sea sponge named SpongeBob SquarePants lives in the city of Bikini Bottom deep in the Pacific Ocean. ',
genre: 'children',
maturity: '0',
slug: 'spongebob',
});
// Crime
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Making a Murderer',
description:
'Exonerated after spending nearly two decades in prison for a crime he did not commit, Steven Avery filed suit against Manitowoc County, Wis., and several individuals involved with his arrest.',
genre: 'crime',
maturity: '18',
slug: 'making-a-murderer',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Long Shot',
description:
'An innocent man is accused of murder, leading his attorney on a wild chase to confirm his alibi using raw footage from a television show.',
genre: 'crime',
maturity: '18',
slug: 'long-shot',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'The Confession Killer',
description:
'Henry Lee Lucas was an American convicted serial killer whose crimes spanned from 1960 to 1983. He was convicted of murdering eleven people and condemned to death for the murder of Debra Jackson, although his sentence would be commuted to life in prison in 1998.',
genre: 'crime',
maturity: '18',
slug: 'the-confession-killer',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'The Innocent Man',
description:
'Henry Lee Lucas was an American convicted serial killer whose crimes spanned from 1960 to 1983. He was convicted of murdering eleven people and condemned to death for the murder of Debra Jackson.',
genre: 'crime',
maturity: '18',
slug: 'the-innocent-man',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'The Staircase',
description:
"In 2001 novelist Michael Peterson's wife died, and he claimed she perished after falling down stairs at their home. The medical examiner, however, determined that she had been beaten with a weapon",
genre: 'crime',
maturity: '18',
slug: 'the-staircase',
});
// Feel-good
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Good Will Hunting',
description:
'Will Hunting, a genius in mathematics, solves all the difficult mathematical problems. When he faces an emotional crisis, he takes help from psychiatrist Dr Sean Maguireto, who helps him recover.',
genre: 'feel-good',
maturity: '12',
slug: 'good-will-hunting',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Forrest Gump',
description:
'Forrest Gump, a man with a low IQ, joins the army for service where he meets Dan and Bubba. However, he cannot stop thinking about his childhood sweetheart Jenny Curran, whose life is messed up.',
genre: 'feel-good',
maturity: '12',
slug: 'forrest-gump',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Juno',
description:
"Social misfit Juno protects herself with a caustic wit, but her unplanned pregnancy has the teen getting more involved in the lives of her baby's adoptive parents than she expected.",
genre: 'feel-good',
maturity: '12',
slug: 'juno',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Midnight In Paris',
description:
'Gil arrives with his fiancee and her family in Paris for a vacation, even as he tries to finish his debut novel. He is beguiled by the city, which takes him to a time past, away from his fiancee.',
genre: 'feel-good',
maturity: '12',
slug: 'midnight-in-paris',
});
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'School of Rock',
description:
"Dewey Finn, an amateur rock enthusiast, slyly takes up his friend's substitute teacher's job. Bearing no qualifications for it, he instead starts training the students to form a band.",
genre: 'feel-good',
maturity: '12',
slug: 'school-of-rock',
});
/* Films
============================================ */
// Drama
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'The Prestige',
description:
'Two friends and fellow magicians become bitter enemies after a sudden tragedy. As they devote themselves to this rivalry, they make sacrifices that bring them fame but with terrible consequences.',
genre: 'drama',
maturity: '15',
slug: 'the-prestige',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Fight Club',
description:
'Discontented with his capitalistic lifestyle, a white-collared insomniac forms an underground fight club with Tyler, a careless soap salesman. The project soon spirals down into something sinister.',
genre: 'drama',
maturity: '15',
slug: 'fight-club',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Kings Speech',
description:
'King George VI tries to overcome his stammering problem with the help of speech therapist Lionel Logue and makes himself worthy enough to lead his country through World War II.',
genre: 'drama',
maturity: '15',
slug: 'kings-speech',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'The Revenant',
description:
'Hugh Glass, a legendary frontiersman, is severely injured in a bear attack and is abandoned by his hunting crew. He uses his skills to survive and take revenge on his companion, who betrayed him.',
genre: 'drama',
maturity: '15',
slug: 'the-revenant',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'The Social Network',
description:
'Mark Zuckerberg creates a social networking site, Facebook, with the help of his friend Eduardo Saverin. But soon, a string of lies tears their relationship apart even as Facebook connects people.',
genre: 'drama',
maturity: '12',
slug: 'the-social-network',
});
// Suspense
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Shutter Island',
description:
'Teddy Daniels and Chuck Aule, two US marshals, are sent to an asylum on a remote island in order to investigate the disappearance of a patient, where Teddy uncovers a shocking truth about the place.',
genre: 'suspense',
maturity: '15',
slug: 'shutter-island',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Gone Girl',
description:
'Nick Dunne discovers that the entire media focus has shifted on him when his wife Amy Dunne disappears on the day of their fifth wedding anniversary.',
genre: 'suspense',
maturity: '15',
slug: 'gone-girl',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Prisoners',
description:
"When the police take time to find Keller Dover's daughter and her friend, he decides to go on a search himself. His desperation leads him closer to finding the truth and also jeopardises his own life.",
genre: 'suspense',
maturity: '15',
slug: 'prisoners',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Seven',
description:
'A serial killer begins murdering people according to the seven deadly sins. Two detectives, one new to the city and the other about to retire, are tasked with apprehending the criminal.',
genre: 'suspense',
maturity: '15',
slug: 'seven',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Zodiac',
description:
'Robert Graysmith, a cartoonist by profession, finds himself obsessively thinking about the Zodiac killer. He uses his puzzle-solving abilities to get closer to revealing the identity of the killer.',
genre: 'suspense',
maturity: '15',
slug: 'zodiac',
});
// Children
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Hotel Transylvania',
description:
'Dracula, who owns a high-end resort for monsters, attempts to keep his daughter from falling in love with Jonathan, a human.',
genre: 'children',
maturity: '0',
slug: 'hotel-transylvania',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Despicable Me',
description:
'Gru, a criminal mastermind, adopts three orphans as pawns to carry out the biggest heist in history. His life takes an unexpected turn when the little girls see him as their potential father.',
genre: 'children',
maturity: '0',
slug: 'despicable-me',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Frozen',
description:
'Anna sets out on a journey with an iceman, Kristoff, and his reindeer, Sven, in order to find her sister, Elsa, who has the power to convert any object or person into ice.',
genre: 'children',
maturity: '0',
slug: 'frozen',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Spirited Away',
description:
'In this animated feature by noted Japanese director Hayao Miyazaki, 10-year-old Chihiro (Rumi Hiiragi) and her parents (Takashi Naitô, Yasuko Sawaguchi) stumble upon a seemingly abandoned amusement park.',
genre: 'children',
maturity: '0',
slug: 'spirited-away',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Up',
description:
"Carl, an old widower, goes off on an adventure in his flying house in search of Paradise Falls, his wife's dream destination.",
genre: 'children',
maturity: '0',
slug: 'up',
});
// Thriller
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Joker',
description:
'Forever alone in a crowd, failed comedian Arthur Fleck seeks connection as he walks the streets of Gotham City.',
genre: 'thriller',
maturity: '15',
slug: 'joker',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'A Quiet Place',
description:
'The Abbott family must now face the terrors of the outside world as they fight for survival in silence. Forced to venture into the unknown, they realize that the creatures that hunt by sound are not the only threats that lurk beyond the sand path.',
genre: 'thriller',
maturity: '15',
slug: 'a-quiet-place',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Black Swan',
description:
'Nina, a ballerina, gets the chance to play the White Swan, Princess Odette. But she finds herself slipping into madness when Thomas, the artistic director, decides that Lily might fit the role better.',
genre: 'thriller',
maturity: '15',
slug: 'black-swan',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Nightcrawler',
description:
'Louis Bloom, a petty thief, realises that he can make money by capturing photographs of criminal activities and starts resorting to extreme tactics to get them.',
genre: 'thriller',
maturity: '15',
slug: 'nightcrawler',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'The Silence of The Lambs',
description:
'Clarice Starling, an FBI agent, seeks help from Hannibal Lecter, a psychopathic serial killer and former psychiatrist, in order to apprehend another serial killer who has been claiming female victims.',
genre: 'thriller',
maturity: '15',
slug: 'the-silence-of-the-lambs',
});
// Romance
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'A Star Is Born',
description:
'After falling in love with struggling artist Ally, Jackson, a musician, coaxes her to follow her dreams, while he battles with alcoholism and his personal demons.',
genre: 'romance',
maturity: '15',
slug: 'a-star-is-born',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Blue Valentine',
description:
'Dean and Cynthia are married with a daughter and their marriage is about to fall apart. Both come from dysfunctional families and struggle to make sense of their relationship.',
genre: 'romance',
maturity: '15',
slug: 'blue-valentine',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'La La Land',
description:
'Sebastian (Ryan Gosling) and Mia (Emma Stone) are drawn together by their common desire to do what they love. But as success mounts they are faced with decisions that begin...',
genre: 'romance',
maturity: '15',
slug: 'la-la-land',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'The Notebook',
description:
"Duke reads the story of Allie and Noah, two lovers who were separated by fate, to Ms Hamilton, an old woman who suffers from Alzheimer's, on a daily basis out of his notebook.",
genre: 'romance',
maturity: '15',
slug: 'the-notebook',
});
firebase.firestore().collection('films').add({
id: getUUID(),
title: 'Titanic',
description:
'Seventeen-year-old Rose hails from an aristocratic family and is set to be married. When she boards the Titanic, she meets Jack Dawson, an artist, and falls in love with him.',
genre: 'romance',
maturity: '15',
slug: 'titanic',
});
}
最佳答案
import Firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
import { seedDatabase } from '../seed'; // comment this after seed is done
const config = {}; // your config goes here
const firebase = Firebase.initializeApp(config);
seedDatabase(firebase); // comment this after seed is done
export { firebase };
所以你需要播种一次,然后在你的数据在 firestore 中评论上面的两行,这样你就没有重复的数据。
关于reactjs - 如何将数据播种到 firebase firestore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63004211/
从 PHP7 开始,为 PRNG 引入了一个新函数:random_int ( http://php.net/manual/en/function.random-int.php ) PHP 手册中没有与
在 .net 核心项目中,我像这样在 Program.cs 文件中播种: var host = BuildWebHost(args); using (var scope = host.Services
我有一张谷歌地图,上面有大约 200 个标记。使用谷歌距离矩阵服务,我可以找到从一个地址到 map 上所有标记的行驶距离。由于 API 限制,我每次调用只能提交 25 个目的地,因此我必须将操作分解为
下面的脚本抛出错误(自定义字段未定义)。我需要以不同的方式传递元素 ID 吗? 我正在尝试使用我要计算的表单字段来为数组播种。它应该迭代数组中的每个表单字段,并用表单元素的值递增 sum 变量。 jQ
我正在学习“Laravel 5 Essentials”中的教程。当我尝试使用命令为我的数据库播种时 php artisan db:seed 我收到错误 [ReflectionException]
我正在关注 docs为 users 表设置种子,该表显示正在使用 User::create class UserTableSeeder extends Seeder { public func
让我首先说明我要完成的任务: 我需要在一定范围内随机生成一组数字 我希望这些数字稍微均匀分布 我需要能够为随机数生成播种,这样,给定一个种子,生成的随机数将始终相同。 在对 drand48()、ran
这个问题在这里已经有了答案: Recommended way to initialize srand? (15 个答案) 关闭 9 年前。 我学习的方法是最初使用 srand(time(NULL))
SQLite 是否支持播种 RANDOM() 的功能与 MySQL 对 RAND() 的处理方式相同? $query = "SELECT * FROM table ORDER BY RAND(" .
我正在使用不支持的 Visual Studio 2010 ,所以我必须播种 default_random_engine .因此,我决定用 rand 播种它如下 srand((unsigned int
在 google OR-tools 库中,“原始”CP-Solver(此处讨论: https://developers.google.com/optimization/cp/original_cp_s
我正在尝试为 AspNetRole 表设置初始系统角色。 播种扩展: public static void EnsureRolesAreCreated(this IApplicationBuilder
我似乎无法弄清楚如何使用 Sequelize 为 ARRAY(ENUM) 播种。当我通过我的应用程序注册用户时,我可以很好地创建一个新用户,但是当我在种子文件中使用 queryInterface.bu
以下代码应创建两个具有相同种子的 Random 对象: System.out.println("System time before: " + System.currentTimeMillis());
尝试从集合中选择伪随机元素时,我看到了非确定性行为,即使 RNG 已播种(示例代码如下所示)。为什么会发生这种情况,我是否应该期望其他 Python 数据类型表现出类似的行为? 注意:我只在 Pyth
关于在 openssl/bn.h 中使用 BN_generate_prime 生成质数的内容,我无法找到答案。另外,我将如何播种此函数使用的任何 PRNG? 单独的问题但与我的代码相关(我正在编写一个
所以,我是 MEAN 堆栈的新手,我在尝试播种 MongoDB 时碰壁了。我正在使用 Mongoose 与数据库进行通信,并且有一堆文档建议我应该能够使用填充的 JSON 文件进行播种。 我尝试过的:
我有一个非常简单的情况:我想使用 testcontainers 测试 AWS 中现有的 mysql 数据库。 我遵循了官方指南( https://www.testcontainers.org/modu
我有一个很长(500K+ 行)的两列电子表格,如下所示: Name Code 1234 A 1234 B 1456 C 4556 A 4556 B 4556
我有一个要播种的数据透视表。除了 PK 和 FK,该表还包含另外两列:Arrival & Departure(类型:时间戳)。我正在使用 Carbon 随机填充前面的列。这是我的代码: $faker
我是一名优秀的程序员,十分优秀!