Skip to content

Instantly share code, notes, and snippets.

View pkosiec's full-sized avatar

Pawel Kosiec pkosiec

View GitHub Profile
@pkosiec
pkosiec / mongo-seeding-example.js
Last active August 2, 2021 11:43
Seed MongoDB database programmatically
const path = require('path');
const { Seeder } = require('mongo-seeding');
const config = {
database: {
name: 'mydbname',
},
dropDatabase: true,
};
const seeder = new Seeder(config);
@pkosiec
pkosiec / custom-mongo-seeding.Dockerfile
Last active November 5, 2018 11:47
Custom Mongo Seeding Docker image example
FROM pkosiec/mongo-seeding:3.0.0
WORKDIR /mydb/
# Copy your project (import data and all dependencies have to be there)
COPY ./mydb /mydb/
# Install external dependencies
RUN npm install
@pkosiec
pkosiec / example-document.json
Created November 1, 2018 22:14
Single MongoDB document definition
{
"name": "{NAME_HERE}",
"email": "[email protected]",
"avatar": "https://placekitten.com/300/300"
}
@pkosiec
pkosiec / example-documents.json
Created November 1, 2018 22:15
JSON is bad to define import data
[
{
"name": "John",
"email": "[email protected]",
"avatar": "https://placekitten.com/300/300"
},
{
"name": "Joanne",
"email": "[email protected]",
"avatar": "https://placekitten.com/300/300"
@pkosiec
pkosiec / example-document.js
Created November 1, 2018 22:16
Example import data in JS
const names = ["John", "Joanne", "Bob", "Will", "Chris", "Mike", "Anna", "Jack", "Peter", "Paul"];
module.exports = names.map(name => ({
name,
email: "[email protected]",
avatar: "https://placekitten.com/300/300",
}))
@pkosiec
pkosiec / example-document-with-randomization.js
Last active October 13, 2020 20:15
Example MongoDB document with randomization
const { getObjectId } = require("mongo-seeding");
const names = ["John", "Joanne", "Bob", "Will", "Chris", "Mike", "Anna", "Jack", "Peter", "Paul"];
const min = 18;
const max = 100;
module.exports = names.map(name => ({
firstName: name,
age: Math.floor(Math.random() * (max - min + 1)) + min,
_id: getObjectId(name),
}))
@pkosiec
pkosiec / example-document-with-typo.json
Created November 1, 2018 22:19
Example MongoDB document with typo
[
{
"name": "John",
"email": "[email protected]",
"age": 18,
},
{
"name": "Bob",
"emial": "[email protected]",
"age": "none",
@pkosiec
pkosiec / example-document.ts
Created November 1, 2018 22:21
Example MongoDB document in TypeScript
import { Person } from '../../models';
const people: Person[] = [
{
name: "John",
email: "[email protected]",
age: 18,
},
{
name: "Bob",
emial: "[email protected]", // <-- error underlined in IDE
@pkosiec
pkosiec / array-example.js
Created November 1, 2018 22:35
MongoDB document definition examples
module.exports = [
{
name: "Dog"
},
{
name: "Cat"
}
]

Keybase proof

I hereby claim:

  • I am pkosiec on github.
  • I am pawelkosiec (https://keybase.io/pawelkosiec) on keybase.
  • I have a public key ASDvl3WH7enT4vOTgLcadLFN_CX8HrcHtfH6tYOJb-3Jvwo

To claim this, I am signing this object: