Skip to content

Commit dc693cc

Browse files
committed
Sesión MongoDB
1 parent 3d61471 commit dc693cc

39 files changed

+47478
-0
lines changed

2023-05-02/mongo-connect/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

2023-05-02/mongo-connect/bun.lockb

6.1 KB
Binary file not shown.

2023-05-02/mongo-connect/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
import mongodb from 'mongodb';
3+
4+
const url = "mongodb://admin:fullstack@localhost:27017?authSource=admin"
5+
const client = new mongodb.MongoClient(url);
6+
7+
await client.connect();
8+
console.log("connected");
9+
10+
const db = client.db("russian");
11+
const tweets = db.collection("tweets");
12+
13+
const result = await tweets.find({ author: '10_GOP' }).limit(3).toArray();
14+
console.log(result);
15+
16+
client.close();
17+
18+

2023-05-02/mongo-connect/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"dependencies": { "bun-types": "^0.5.8", "mongodb": "^5.3.0" },
3+
"type": "module"
4+
}

2023-05-02/mongodb/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '3.1'
2+
3+
services:
4+
mongo:
5+
image: mongo
6+
restart: always
7+
environment:
8+
MONGO_INITDB_ROOT_USERNAME: admin
9+
MONGO_INITDB_ROOT_PASSWORD: fullstack
10+
ports:
11+
- 27017:27017
12+
volumes:
13+
- data:/data/db
14+
volumes:
15+
data:

2023-05-02/mongodb/mongodb-example.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
const mongodb = require('mongodb');
3+
4+
const url = "mongodb://admin:fullstack@localhost:27017";
5+
const client = new mongodb.MongoClient(url, { useUnifiedTopology: true });
6+
7+
async function main() {
8+
await client.connect();
9+
const db = client.db("test");
10+
const result = await db.collection("foo").insertMany([
11+
{ a: 1, b: 2, c: "hola" },
12+
{ bla: "bla", bli: "bli" },
13+
]);
14+
console.log(result);
15+
client.close();
16+
}
17+
18+
main();

2023-05-02/mongodb/open-db-console.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
docker exec -it db-mongo-1 mongosh -u admin -p fullstack

2023-05-02/mongodb/package-lock.json

Lines changed: 330 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)