Mongo DB Flashcards
What is the MongoDB syntax to write a JSON range query?
{fieldname:{$gte: numx, $lt: numy}}
What is the syntax to create a database?
use
What is the MongoDB syntax to find a collection within the command line?
db.collection_name.find()
what is the Mongo CLI syntax to insert multiple documents?
db.post.insertMany([])
How do you specify, or access field in an embedded document?
”..“
To specify or access a field of an embedded document with dot notation, concatenate the embedded document name with the dot (.) and the field name, and enclose in quotes:
db.post.find({‘username.fname’:’John’})
What is the syntax to find an array length?
db..find( { “tags”: { $size: 3 } } )
What is the syntax for AND in a ‘find’ clause?
db..find({$and:[{“Username”:”Alex”},{“title”:”NoSQL Database”}]}).pretty()
How do you use find with a specific clause
db.post.find( {:]} )
example
db.post.find( {tags:[ ‘mongodb’, ‘database’, ‘NoSQL’]} )
What is the MongoDB command line syntax to query an array by array length
db.find({:})
example
db.post.find( { “tags”: {$size:3}})
What is the mongoDB command line syntax to update a document?
db.mycol.update({:},{$set:{:}})
What is the MongoDB command line syntax to insert multiple documents into a collections
db. .insertMany([{:,,,:},{BSONFILE2},{BSONFILE3}])
* FYI:: ‘insertMany’ takes in an array.
What is the MongoDB command line syntax to delete a collection
db..drop()
What is the MongoDB command line syntax to rename a collection
db..renameCollection()
What is the MongoDB CLI syntax to iterate through a field to see if it equates to a boolean statement?
db.records.aggregate( [
{ $project: { : { $eq: [ “”, { $literal:} ] } } }
] )
What formats does MongoDB accept?
Use Json and Bson for documents.