MongoDB
Esta página todavía no se ha traducido — se muestra en su idioma original:Català
Introducció
Entorn de treball
Arranca la base de dades:
start-process -NoNewWindow mongod.exeCrea un projecte amb Bun:
mkdir monogdb
cd monogdb
bun init -yAfegeix una dependència amb mongodb:
bun add mongodbObre el projecte amb WebStorm.
Inserir documents
You can insert a document into a collection using the collection.insertOne() method. To insert a
document, define an object that contains the fields and values that you want to store. If the specified
collection does not exist, the insertOne() method creates the collection.
Crea el fitxer fish.ts
A continuació, insereix un peix a la col·lecció fish de la base de dades ocean.
// fish.ts
// MongoDB deployment's connection string
// Create a new client and connect to MongoDB
try
// Connect to the "ocean" database and access its "fish" collection
// Delete all the fish from the collection
await
// Create a document to insert
// Insert the defined document into the "ocean" collection
// Print the ID of the inserted document
`A document was inserted with the _id: `
} finally // Close the MongoDB client connection
await
}Estás leyendo una vista previa.
Inicia sesión para leer el artículo completo. Cualquier cuenta abre 4 artículos gratuitos al mes; el alumnado y el profesorado leen las páginas de su curso sin límite.
Iniciar sesión