mongod --dbpath=data - set the database and run mongo - mongosh db use nucampsite db db.help() Next, create a collection named campsites, and insert a new campsite document in the collection: db.campsites.insert({ name: "React Lake Campground", description: "Test" }); Then to print out the campsites in the collection, type: db.campsites.find().pretty(); Note the "_id" that was automatically assigned to the campsite. Next, we will learn the information encoded into an instance of ObjectId by typing the following at the prompt: const id = new ObjectId(); id.getTimestamp(); To exit the REPL shell, type exit at the prompt: exit
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter