Data-Association-MongoDB is a Node.js project that demonstrates data association using MongoDB. The project includes a simple Express server with routes to create users and posts, and establish relationships between them.
- Node.js and npm installed
- MongoDB installed and running
-
Clone the repository:
git clone https://github.com/A-Tetarwal/Data-Association-MongoDB.git cd Data-Association-MongoDB
-
Install dependencies:
npm install
-
Start the server:
node app.js
Data-Association-MongoDB
│
├── models
│ ├── user.js # User model definition
│ └── post.js # Post model definition
├── app.js # Main application file
├── package.json # Project metadata and dependencies
└── README.md # Project documentation
- Route:
/
- Method:
GET
- Description: Returns a welcome message.
- Response:
{ "message": "aaj magic hoga" }
- Route:
/create
- Method:
GET
- Description: Creates a new user with predefined details.
- Response:
{ "username": "jaani", "age": 25, "email": "[email protected]", "posts": [] }
- Route:
/post/create
- Method:
GET
- Description: Creates a new post associated with a predefined user.
- Response:
{ "user": { "_id": "user_id", "username": "jaani", "age": 25, "email": "[email protected]", "posts": ["post_id"] }, "post": { "_id": "post_id", "postdata": "how's everything going?", "user": "user_id" } }
- Fields:
username
: Stringage
: Numberemail
: Stringposts
: Array of ObjectIds (references to posts)
- Fields:
postdata
: Stringuser
: ObjectId (reference to a user)
- The project demonstrates basic data association in MongoDB using Mongoose.
- The user and post creation routes use hardcoded values for simplicity.
Feel free to modify this README according to your project's specific details and requirements.