mongodb Flashcards

1
Q

how to load up mongo

A

mongod on command line

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

mondodb - what is the equivalent of an sql table

A

collection

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

mongodb - delete document where category is sandwich

A

@col.remove({‘category’ => “sandwich”}) # note how it uses same parameters as in find method

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

mongodb - equivalent of sql column

A

bson field

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

mongodb - equivalent of sql primary key

A

_id field

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

mongodb - equivalent of sql row

A

bson document

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

mongodb - find all emails (a field) with gmail in it

A

collection.find {:email => /gmail/i }

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

mongodb - get all unique tags in the system

A

posts.distinct(‘tags’)

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

mongodb - how to decide whether to embed an object or not

A

look at how you work with objects in your software an entity should get its own collection if you frequently work with that entity by itself.

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

mongodb - what’s wrong with this data structure: {“_id”=>BSON::ObjectId4eeff4dad27d20f1b500011e, “name”=>{“Margaret Nicholson”=>[#data]}}

A

should be: {“_id”=>BSON::ObjectId4eeff4dad27d20f1b500011e, “name”=>”Margaret Nicholson” “data”=>[]} why? easier access with queries (db.facebook_likes.find{name:/Margaret/})

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

mongodb - why don’t you need a created_at column

A

since the _id includes a timestamp thus this is chronological order posts.find.sort( [[‘_id’, -1]] )

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

mongodb posts.find( :tags => ‘mongo’ ) add an index to make this more efficient

A

posts.create_index(‘tags’)

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