The document discusses how to use the MongoDB shell, which is a JavaScript interpreter with built-in support for connecting to MongoDB. It describes how the shell can be used for interactive development, testing, administration, and learning MongoDB. It provides details on running the shell, helpers, completion, editing, getting help, and working with cursors. It also notes some gotchas with using JavaScript and recommends further resources for using MongoDB.
The document discusses the benefits of exercise for mental health. Regular physical activity can help reduce anxiety and depression and improve mood and cognitive function. Exercise causes chemical changes in the brain that may help protect against mental illness and improve symptoms.
The document discusses indexing and query optimization in MongoDB. It provides an overview of how indexes work, how to create and maintain indexes, and when indexes can and cannot be used to optimize queries. It emphasizes the importance of compound indexes and provides examples of how to use indexes to improve queries. The document also covers the query optimizer and profiling features in MongoDB.
Gave a talk at StartCon about the future of Growth. I touch on viral marketing / referral marketing, fake news and social media, and marketplaces. Finally, the slides go through future technology platforms and how things might evolve there.
32 Ways a Digital Marketing Consultant Can Help Grow Your BusinessBarry Feldman
How can a digital marketing consultant help your business? In this resource we'll count the ways. 24 additional marketing resources are bundled for free.
The document discusses how to use the MongoDB shell, which is a JavaScript interpreter with built-in support for connecting to MongoDB. It describes how the shell can be used for interactive development, testing, administration, and learning MongoDB. It provides details on running the shell, helpers, completion, editing, getting help, and working with cursors. It also notes some gotchas with using JavaScript and recommends further resources for using MongoDB.
The document discusses the benefits of exercise for mental health. Regular physical activity can help reduce anxiety and depression and improve mood and cognitive function. Exercise causes chemical changes in the brain that may help protect against mental illness and improve symptoms.
The document discusses indexing and query optimization in MongoDB. It provides an overview of how indexes work, how to create and maintain indexes, and when indexes can and cannot be used to optimize queries. It emphasizes the importance of compound indexes and provides examples of how to use indexes to improve queries. The document also covers the query optimizer and profiling features in MongoDB.
Gave a talk at StartCon about the future of Growth. I touch on viral marketing / referral marketing, fake news and social media, and marketplaces. Finally, the slides go through future technology platforms and how things might evolve there.
32 Ways a Digital Marketing Consultant Can Help Grow Your BusinessBarry Feldman
How can a digital marketing consultant help your business? In this resource we'll count the ways. 24 additional marketing resources are bundled for free.
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
Mongophilly cool-features-2011-04-26
1. Map/Reduce, geospatial search, and other Cool
Features
Richard M Kreuter
10gen Inc.
richard@10gen.com
April 26, 2011
Map/Reduce, geospatial search, and other Cool Features — MongoPhilly
2. Things I’ll cover
Array tricks
The findAndModify command
Map/Reduce, geospatial search, and other Cool Features — MongoPhilly
3. Array tricks
Suppose your collection looked like this:
> db . a r r a y s . f i n d ( )
{ ” i d ” : 1 , ” t a g s ” : [ ” a ” , ”b ” , ” c ” ] }
{ ” i d ” : 2 , ” t a g s ” : [ ”b ” , ” c ” , ”d” ] }
{ ” i d ” : 3 , ” t a g s ” : [ ” c ” , ”d ” , ” e ” ] }
Map/Reduce, geospatial search, and other Cool Features — MongoPhilly
4. Array tricks, continued
....then consider the following queries:
db . arrays . f i n d ({ t a g s : ’a ’}) // matches 1
db . arrays . f i n d ({ t a g s : ’c ’}) // matches 1 , 2 , 3
db . arrays . f i n d ({ t a g s : { $in : [ ’ a ’ , ’ e ’ ] } } ) // 1 and 3
db . arrays . f i n d ({ t a g s : {$all : [ ’ a ’ , ’ e ’ ] } } ) // no ma
db . arrays . f i n d ({ t a g s : {$all : [ ’ c ’ , ’ d ’ ] } } ) // match
Map/Reduce, geospatial search, and other Cool Features — MongoPhilly
5. Array tricks, continued continued
As of v1.5.1 (and so v1.6) you can project slices of arrays with the
$slice operator
// Will return { id :1 , tags : [” a ”]}
db . a r r a y s . f i n d ({ id :1} , { tags : { $ s l i c e :1}})
// Will return { id :1 , tags : [” c ”]}
db . a r r a y s . f i n d ({ id : 1 } , { t a g s : { $ s l i c e : −1}})
// Will return { id :1 , tags : [” b” , ”c ”]}
db . a r r a y s . f i n d ({ id :1} , { tags : { $ s l i c e :[1 ,2]}})
Map/Reduce, geospatial search, and other Cool Features — MongoPhilly
6. Array tricks, continued continued continued
And you can also update portions of documents matched by the
update’s selector with the positional operator, $:
> db . a r r a y s . u p d a t e ( { t a g s : ’ b ’ } ,
{ $ s e t : { ’ t a g s . $ ’ : ’X’ } } ,
false , true );
> db . a r r a y s . f i n d ( ) ;
{ ” i d ” : 1 , ” t a g s ” : [ ” a ” , ”X” , ” c ” ] }
{ ” i d ” : 2 , ” t a g s ” : [ ”X” , ” c ” , ”d” ] }
{ ” i d ” : 3 , ” t a g s ” : [ ” c ” , ”d ” , ” e ” ] }
Map/Reduce, geospatial search, and other Cool Features — MongoPhilly
7. findAndModify
db . c o u n t e r s . s a v e ( { i d : ’ some i d ’ , v a l u e : 0 } ) ;
function get (){
r e t u r n db . c o u n t e r s . f i n d A n d M o d i f y ( {
q u e r y : { i d : ’ some i d ’ } ,
update :{ $inc :{ v a l u e :1}}})
}
> get ()
{ ” i d ” : ” some i d ” , ” v a l u e ” : 0 }
> get ()
{ ” i d ” : ” some i d ” , ” v a l u e ” : 1 }
> get ()
{ ” i d ” : ” some i d ” , ” v a l u e ” : 2 }
> get ()
{ ” i d ” : ” some i d ” , ” v a l u e ” : 3 }
Map/Reduce, geospatial search, and other Cool Features — MongoPhilly
8. findAndModify, continued
db . r e s o u r c e s . s a v e (
{ f r e e : 90 ,
buckets : [ { use : 10 , c l i e n t : ” f r e d ” } ,
{ use : 0 , c l i e n t : n u l l } ,
. . . ] });
function allocate bucket ( quantity , c l i e n t ) {
r e t u r n db . r e s o u r c e s . f i n d A n d M o d i f y (
{ q u e r y : { ’ b u c k e t s . use ’ : 0 ,
f r e e : { $gt : q u a n t i t y } } ,
u p d a t e : { $ i n c : { f r e e : −q u a n t i t y } ,
$set :
{ ’ b u c k e t s . $ . use ’ : q u a n t i t y ,
’ buckets . $ . c l i e n t ’ : c l i e n t } } })
Map/Reduce, geospatial search, and other Cool Features — MongoPhilly