Nuestro equipo redactor ha estado mucho tiempo investigando para dar solución a tu duda, te regalamos la solución y nuestro objetivo es servirte de gran ayuda.
Ejemplo 1: comandos de shell mongo
show dbs # <=> Print a list of all databases on the server.
use # <=> Switch current database to
show collections # <=> Print a list of all collections for current database.
db.people.insert(name:"Ashwin",gender:"m") # <=> Inserts a new "person" collection with a new object in that collection
db.people.find() # <=> Find all persons in the collection
db.people.update(name:"Ashwin",gender:"f") # <=> Updates the selected (1st parameter) person with new value(2nd parameter)
db.people.remove(name:"Ashwin") # <=> Remove where name is "Ashwin"
db.people.drop() # <=> Delete the "people" collection
Ejemplo 2: mongodb cmds
MongoDB
mongod --dbpath /users/yulin/Documents/data/db
mongo (once mongod is ran OPEN ANOTHER TERMINAL THconnect to MongoDB)
ctrl-l to clear screen
show dbs
use put db name here
show collections
use put collection name here ex. - use quizzes
use dbs ( or cd .. -- to go back dbs level)
or just stay @ db level
db.createCollection(“quizzes”)
db.quizzes.find().pretty()
db.quizzes.insert(“title”: 1) (crud stuff)
db.quizzes.find(“title”: 1)
db.quizzes.remove() (remove all)
db.quizzes.remove(title: 1)
db.quizzes.update (title: 1, title, 2) (update by replaceing the entire object)
db.quizzes.update (name: “yulin”, $set:title: “Quiz 2”) (update by appending object)
db.quizzes.find(avg: $gt: 85) (greater than)
db.quizzes.find(avg: $gte: 85) (greater than or equal to)
db.quizzes.find(avg: $lte: 85) (less than)
Ejemplo 3: inicia mongodb en la terminal
Start a terminal for your mongo server
Go to /bin directory
Run the command./mongod
Start a terminal for your mongo shell
Go to /bin directory
Run the command (make sure you put the name of the database)./mongo test
Reseñas y calificaciones
Recuerda recomendar esta sección si si solucionó tu problema.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)