Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ajyounguk/mongodb-crud-client
Simple Mongo CRUD client in node.js for mongoDB
https://github.com/ajyounguk/mongodb-crud-client
crud css demo example example-code express html mongodb mongoose nodejs
Last synced: about 3 hours ago
JSON representation
Simple Mongo CRUD client in node.js for mongoDB
- Host: GitHub
- URL: https://github.com/ajyounguk/mongodb-crud-client
- Owner: ajyounguk
- License: mit
- Created: 2018-03-01T11:03:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-20T09:33:54.000Z (almost 2 years ago)
- Last Synced: 2024-10-17T11:47:40.896Z (about 1 month ago)
- Topics: crud, css, demo, example, example-code, express, html, mongodb, mongoose, nodejs
- Language: JavaScript
- Homepage:
- Size: 323 KB
- Stars: 3
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## MongoDB CRUD in Node.js - Example / Demo code
## What is this?
Demo code that excercises MongoDB Create Read Update Delete (CRUD) operations with the mongoose npm module![Alt text](/screenshots/mongo_read.png?raw=true)
## Contains
- /config = mongo connection config (sample)
- /controller = controller code with routes and DB operations in personController.js. and DB setup+purge API in setupController
- model = person DB data model
- /public = cascading stylesheet
- /views = EJS views / HTML UI
- / = app.js main webserver code & package.json### Mongo Client UI Functionality:
- Add a person - CREATE Crud
- List person(s) - READ cRud
- Update person (needs MongoID from list function) - UPDATE crUd
- Delete person (needs MongoID from list function) - DELETE cruD### Setup API
purge mongo collection = point browser at http://0.0.0.0:3000/person/purge
setup / seed data in collection = http://0.0.0.0:3000/person/setup## Installation overview
### Install mongo DB with auth model
See https://docs.mongodb.com/manual/installation/### Clone Repo an install module dependencies
```
git clone https://github.com/ajyounguk/mongodb-crud-demo
cd mongodb-crud-demo
npm install
```### Mongo Config
Copy /config/mongo-config-sample.json to mongo-config.json
Needs mongo username and password and mongo running with --auth
```
cp config-sample.json config.json
```## How to run it
```
node app.js
```point your browser at the lport 3000 to load Client
http://0.0.0.0:3000## DB user credentials example
This is **NOT** a hardened/strong security model for mongo, but a simple set of reference creds to get you started:1. Start mongo with no auth model:
```
mongod
```2.
Connect to mongo cli:
```
mongo
```3. Create database admin user in mongo cli:
```
use admin
db.createUser(
{
user: "admin",
pwd: "mypassword",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
```4. Restart db with authentication model on:
```
mongod -- auth
```5. Connect to mongo cli and login with admin user:
```
mongouse admin
db.auth("admin", "mypassword" )
```6. Create new database (data) and database users
*PS: if databse does not exist already, it's created*```
Use data
db.createUser(
{
user: "data_dev",
pwd: "devpassword",
roles: [
{ role: "readWrite", db: "data" }
]
}
)
db.createUser(
{
user: "data_admin",
pwd: "adminpassword",
roles: [
{ role: "dbOwner", db: "data" }
]
}
)
```7. Create (person) collection in (data) databse
```
{
Create : "person"
}
```8. Update the mongo connection configuration file (/config/mongo-config.json). Using the example dev database user above the config file would look like:
```
{
"mongourl": "mongodb://data_dev:[email protected]:27017/data"
}
```## More Info
For more information on MongoDB:
https://www.mongodb.com/what-is-mongodbFor more information on Express:
https://www.npmjs.com/package/expressFor more information on Mongoose:
https://www.npmjs.com/package/mongoose### EOF Readme.