![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
A little node module that will allow a user to clear a mongo database and then populate it from a given json file.
A build with testing MEAN applications in mind. Allow a developer to write the test data for and populate the database then tear it down.
I built this to help with testing MEAN stack applications. So, you may be asking "Why did you do this?" or "Why not use RAKE?" or "Why not use another packages that do something similar?". My answer is part "I couldn't find exactly what I needed" and part "It sounded fun to write my own package to do this".
To explain the first part more I will break down in to my use cases.
To explain the second part more...it sounded fun and it was.
TL;DR: I wanted it my way and I wanted to do it. I wonder if these are supposed to go at the top...
This is where you have a directory filled with JSON files that were created from a mongoexport
.
NOTE: make sure to use --jsonArray when exporting data from tables. Similar mongoexport --db PetShop --collection Food --out Food.json --jsonArray
mongoSeed.load("localhost",27017, "<name_of_database>", "<seed_directory>", "dir", function (err) {
//..do what ever you need
});
A file is similar to the directory seed. You have a file with an object in it where each property is a collection name and the value is an array of documents for that collection. This also supports two different data formats. The MongoDB Extended JSON(EXTENDED) or the JSON recognized by the node mongodb driver(DRIVER).
{
"dataFormat": "<Type-of-json>",// supported types EXTENDED or DRIVER
"table_Name": [/*Each document as an individual object in the array*/]
/*...*/
"table_Name_n": [/*Each document as an individual object in the array*/]
}
mongoSeed.load("localhost",27017, "<name_of_database>", "<path_to_file>", "file", function (err) {
//..do what ever you need
});
So loading from a function means you have a node module somewhere that returns JSON in the same format the mongodb node drive uses. I wanted to use some of the mongoDB client helpers to set up data sets.
module.exports = function(){
return {
"table_Name": [/*Each document as an individual object in the array*/]
/*...*/
"table_Name_n": [/*Each document as an individual object in the array*/]
};
};
mongoSeed.load("localhost",27017, "<name_of_database>", "<path_function_def>", "function", function (err) {
//..do what ever you need
});
COMING SOON
Self-explanatory. Back up a database that causes certain test cases load it in the test enviroment then tear it down. Well when this is added....
COMING SOON
COMING SOON
FAQs
Built with testing MEAN applications in mind. Gives a developer a way to populate mongo database from different data sources; functions, files, directories of JSON files.
The npm package mongo-seed receives a total of 0 weekly downloads. As such, mongo-seed popularity was classified as not popular.
We found that mongo-seed demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.