(early draft, work in progress)
This Django application provides a simple web interface for inserting JSON arrays into MongoDB.
Users can input a JSON array, which is then processed and inserted into specified MongoDB collections based on the content of the array. The app is designed to handle arrays of album data, sorting them into "known albums" and "unknown data" collections based on the presence of the numberOfTracks
field.
- Web form for inputting JSON arrays.
- Validation to ensure the input is a valid JSON array.
- Insertion of valid arrays into MongoDB collections.
- Separation of data into "known albums" and "unknown data" based on the presence of specific fields.
- Error handling for database connection issues.
- Minimalistic design for easy use.
- No multiple entry of data, just a single JSON array.
Before you start, make sure you have the following installed:
- Python (3.8 or newer)
- Django (3.x or newer)
- PyMongo
- MongoDB server running locally or accessible via a connection URI.
-
Clone the Repository
git clone https://github.com/kod3000/django-music-collection.git cd django-music-collection
-
Install Dependencies
Inside the project directory, install the required Python packages:
pip install django pymongo dnspython python-dotenv
or
pip install -r requirements.txt
-
Configuration
Setup the environment variables in a
.env
file in the folder 'music_collection'. The file should contain the following:MONGO_URI=your_mongodb_uri MONGO_DATABASE_NAME=your_database_name
-
Run Migrations
Although this application primarily uses MongoDB, ensure your Django project is ready to go:
python manage.py migrate
-
Start the Development Server
python manage.py runserver
Navigate to
http://127.0.0.1:8000/albums/insert/
to access the form.
-
Inserting an Album
On the form page (
/albums/insert/
), enter a JSON array in the input field and submit the form. The array should contain objects with or without anumberOfTracks
field to differentiate between known albums and unknown data.Example array input:
[ {"albumName": "Sample Album 1", "numberOfTracks": 10}, {"albumName": "Unknown Data", "someField": "someValue"} ]
-
Viewing Results
Upon submission, if the array is successfully processed and inserted, you'll see a message indicating the number of albums inserted. If the database connection fails, an error message will be displayed.
- The application handles errors related to database connections and invalid input formats, displaying appropriate messages to the user.
- Ensure your MongoDB server is running and accessible to avoid connection errors.
Contributions are welcome! Feel free to submit a pull request or open an issue if you find a bug or have a feature request.
This project is licensed under the MIT License. See the LICENSE file for details.
This project was built using the following technologies:
If you find this project useful, please consider giving it a star. Thank you!