i want to see a mongodb table in shell code example
Example 1: list all collections in the MongoDB shell
JavaScript (shell):
db.getCollectionNames()
Node.js:
db.listCollections()
Example 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)