-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinsertDonToUser.js
More file actions
31 lines (26 loc) · 1 KB
/
Copy pathinsertDonToUser.js
File metadata and controls
31 lines (26 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { MongoClient, ObjectId } = require('mongodb');
const uri = "mongodb://127.0.0.1/vehahavtem";
async function insertDonation() {
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
try {
await client.connect();
const database = client.db('vehahavtem');
const donationsCollection = database.collection('donations');
const newDonation = {
itemName: 'Winter Jacket',
quantity: 10,
category: 'Clothing',
condition: 'Gently Used',
expirationDate: new Date('2024-11-30'),
description: 'Winter jackets in various sizes and colors',
pickupAddress: '123 Main St',
donor: new ObjectId('66740b0aa5f6d17e945c2a34'), // Replace with the actual user ID
status: 'Pending'
};
const result = await donationsCollection.insertOne(newDonation);
console.log(`New donation inserted with the following id: ${result.insertedId}`);
} finally {
await client.close();
}
}
insertDonation().catch(console.error);