Mongo DB Flashcards

1
Q

What is the MongoDB syntax to write a JSON range query?

A

{fieldname:{$gte: numx, $lt: numy}}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the syntax to create a database?

A

use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the MongoDB syntax to find a collection within the command line?

A

db.collection_name.find()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is the Mongo CLI syntax to insert multiple documents?

A

db.post.insertMany([])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you specify, or access field in an embedded document?

A

”..“

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’})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the syntax to find an array length?

A

db..find( { “tags”: { $size: 3 } } )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the syntax for AND in a ‘find’ clause?

A

db..find({$and:[{“Username”:”Alex”},{“title”:”NoSQL Database”}]}).pretty()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you use find with a specific clause

A

db.post.find( {:]} )

example
db.post.find( {tags:[ ‘mongodb’, ‘database’, ‘NoSQL’]} )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the MongoDB command line syntax to query an array by array length

A

db.find({:})

example
db.post.find( { “tags”: {$size:3}})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the mongoDB command line syntax to update a document?

A

db.mycol.update({:},{$set:{:}})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the MongoDB command line syntax to insert multiple documents into a collections

A

db. .insertMany([{:,,,:},{BSONFILE2},{BSONFILE3}])

* FYI:: ‘insertMany’ takes in an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the MongoDB command line syntax to delete a collection

A

db..drop()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the MongoDB command line syntax to rename a collection

A

db..renameCollection()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the MongoDB CLI syntax to iterate through a field to see if it equates to a boolean statement?

A

db.records.aggregate( [
{ $project: { : { $eq: [ “”, { $literal:} ] } } }
] )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What formats does MongoDB accept?

A

Use Json and Bson for documents.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the normalized data model? and when should you use it?

A

Normalized data models describe relationships using references between documents.

17
Q

In general, when should you use normalized data models?

A

➢ when embedding would result in duplication of data but would not provide sufficient read performance advantages to outweigh the implications of the duplication.
➢ to represent more complex many-to-many relationships
➢ to model large hierarchical data sets.

18
Q

Per the MongoDB University course, what argument can we pass through so that mongo DB continues inserting even if it contacts an error

A

{
‘ordered’: false
}

19
Q

in MongoDB, what syntax goes after a projection query to get rid of the primary key (or any other field in a projection for that matter)

A

Setting a file to ‘:0’ in the projection field

I.E. _id:0

db.COLLECTIONNAME.find({FILTER(S)}, {PROJECTION, _id:0}

E.G: db.movies.find({genre:’drama’},{title, _id=0}

20
Q

In MongoDB, what syntax goes within projection parameter of query to explicitly return respective field, and exclude all others

A

set a respective field to ‘1’

E.G.: db.movies.find({genre:’drama’},{title:1}

21
Q

What method call is used to remove a specific field

A

$unset

22
Q

What does upsert stand for in MongoDB. In which line does it appear in a Mongo query?

A

if exists update, if not then insert. it appears as the third parameter in an update

23
Q

what does the $all operator do?

A

helps you find a combination of values for a given array within a query

e. g.
db. movies.find({genres:{$all: ‘Romance’, ‘comedy’,’action’}},{title:0})

24
Q

what function can you use to get a count of a query

A

.count()

e. g.
find. movies.find({countries:{$size:1}}).count()

25
Q

what are the three popular array operators shown in MongoDB?

A

1) $all: – takes in an array []
2) $size: (is enclosed within {})
3) $elemMatch: (enclosed within {} )

bonus:
4) $in: [ ] ## takes in an array
5) $nin [ ]

26
Q

When are $and and $or used during a MongoDB?

A

When the query has two parameters for the same field. Otherwise, a query is only ran with the second search parameter for the given field.

db.post.find({$and:[arg1, arg2]})

27
Q

What coding language does the MongoDB shell interpret in?

A

The Mongo shell is a JavaScript.

28
Q

how is $in used in MongoDB queries?

A

db.inventory.find( { qty: { $in: [ 5, 15 ] } } )

29
Q

What is the syntax in Mongo for $elematch queries? what can you not specify

A

{ : { $elemMatch: { query1, query2, … } } }

You cannot specify a $where expression in an $elemMatch.
You cannot specify a $text query expression in an $elemMatch.