Setup:
run as root > mkdir -p /data/db
run as root > mongod
(--rest switch starts with rest interface)
create database abcdb:
> mongo abcdb
>_ (prompt will appear)
(db won't be persist unless data inserted)
insert data, into a collection coll:
> db.coll.insert( "lang": "english", "alphabets": ["a","b","c"...], "style":"ltr")
json object will be created in db as follows:
"book":{
"coll":[
{ "lang": "english", "alphabets": ["a","b","c"...], "style":"ltr" }
]
}
to see rows in collections:
> db.coll.find()
to see all the functions of any object use help() function
> db.help()
> db.coll.help()
to see all databases
> show dbs
to see the definition of function, enter function name without parenthesis
>db.coll.find
custom function
> function myFunctionLanguage(lang, style) {
... db.towns.insert(lang:lang, style:style);
... }
find function may take object Id as first argument or condition filter, and columns to show in result in second argument
find time taken by query to execute (need of index?)
> find(...).explain()
create index:
>db.coll.ensureIndex(...)
queries profiling:
> db.setProfilingLevel(2)
>db.system.profile.find()
run as root > mkdir -p /data/db
run as root > mongod
(--rest switch starts with rest interface)
create database abcdb:
> mongo abcdb
>_ (prompt will appear)
(db won't be persist unless data inserted)
insert data, into a collection coll:
> db.coll.insert( "lang": "english", "alphabets": ["a","b","c"...], "style":"ltr")
json object will be created in db as follows:
"book":{
"coll":[
{ "lang": "english", "alphabets": ["a","b","c"...], "style":"ltr" }
]
}
to see rows in collections:
> db.coll.find()
to see all the functions of any object use help() function
> db.help()
> db.coll.help()
to see all databases
> show dbs
to see the definition of function, enter function name without parenthesis
>db.coll.find
custom function
> function myFunctionLanguage(lang, style) {
... db.towns.insert(lang:lang, style:style);
... }
find function may take object Id as first argument or condition filter, and columns to show in result in second argument
find time taken by query to execute (need of index?)
> find(...).explain()
create index:
>db.coll.ensureIndex(...)
queries profiling:
> db.setProfilingLevel(2)
>db.system.profile.find()
No comments:
Post a Comment