블로그 이미지
너덜

calendar

1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

Notice

Tag

'db'에 해당되는 글 3

  1. 2012.04.04 mysql
  2. 2012.04.04 ./mongo
  3. 2012.04.04 몽고DB 시작하기.
2012. 4. 4. 17:45 db/mysql
posted by 너덜
2012. 4. 4. 13:57 db/mongoDB

[root@db02 bin]# ./mongo
MongoDB shell version: 2.0.4
connecting to: test
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
rs.help() help on replica set methods
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce

show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries with time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memory, 'global' is default
use <db_name> set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
>

> db.help()
DB methods:
db.addUser(username, password[, readOnly=false])
db.auth(username, password)
db.cloneDatabase(fromhost)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
db.createCollection(name, { size : ..., capped : ..., max : ... } )
db.currentOp() displays the current operation in the db
db.dropDatabase()
db.eval(func, args) run code server-side
db.getCollection(cname) same as db['cname'] or db.cname
db.getCollectionNames()
db.getLastError() - just returns the err msg string
db.getLastErrorObj() - return full status object
db.getMongo() get the server connection object
db.getMongo().setSlaveOk() allow this connection to read from the nonmaster member of a replica pair
db.getName()
db.getPrevError()
db.getProfilingLevel() - deprecated
db.getProfilingStatus() - returns if profiling is on and slow threshold
db.getReplicationInfo()
db.getSiblingDB(name) get the db at the same server as this one
db.isMaster() check replica primary status
db.killOp(opid) kills the current operation in the db
db.listCommands() lists all the db commands
db.logout()
db.printCollectionStats()
db.printReplicationInfo()
db.printSlaveReplicationInfo()
db.printShardingStatus()
db.removeUser(username)
db.repairDatabase()
db.resetError()
db.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into { cmdObj : 1 }
db.serverStatus()
db.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all
db.shutdownServer()
db.stats()
db.version() current version of the server
db.getMongo().setSlaveOk() allow queries on a replication slave server
db.fsyncLock() flush data to disk and lock server for backups
db.fsyncUnock() unlocks server following a db.fsyncLock()
>

> db.mycoll.help()
DBCollection help
db.mycoll.find().help() - show DBCursor help
db.mycoll.count()
db.mycoll.dataSize()
db.mycoll.distinct( key ) - eg. db.mycoll.distinct( 'x' )
db.mycoll.drop() drop the collection
db.mycoll.dropIndex(name)
db.mycoll.dropIndexes()
db.mycoll.ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDups
db.mycoll.reIndex()
db.mycoll.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
e.g. db.mycoll.find( {x:77} , {name:1, x:1} )
db.mycoll.find(...).count()
db.mycoll.find(...).limit(n)
db.mycoll.find(...).skip(n)
db.mycoll.find(...).sort(...)
db.mycoll.findOne([query])
db.mycoll.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )
db.mycoll.getDB() get DB object associated with collection
db.mycoll.getIndexes()
db.mycoll.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
db.mycoll.mapReduce( mapFunction , reduceFunction , <optional params> )
db.mycoll.remove(query)
db.mycoll.renameCollection( newName , <dropTarget> ) renames the collection.
db.mycoll.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
db.mycoll.save(obj)
db.mycoll.stats()
db.mycoll.storageSize() - includes free space allocated to this collection
db.mycoll.totalIndexSize() - size in bytes of all the indexes
db.mycoll.totalSize() - storage allocated for all data and indexes
db.mycoll.update(query, object[, upsert_bool, multi_bool])
db.mycoll.validate( <full> ) - SLOW
db.mycoll.getShardVersion() - only for use with sharding
db.mycoll.getShardDistribution() - prints statistics about data distribution in the cluster
>

'db > mongoDB' 카테고리의 다른 글

몽고DB 시작하기.  (0) 2012.04.04
posted by 너덜
2012. 4. 4. 13:56 db/mongoDB

몽고DB

mkdir -p /data/db
http://www.mongodb.org

http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart
http://www.mongodb.org/display/DOCS/SQL+to+Aggregation+Framework+Mapping+Chart
http://bsonspec.org/
http://json.org/json-ko.html


wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.4.tgz

tar xvzf mongodb-linux-x86_64-2.0.4.tgz
mv mongodb-linux-x86_64-2.0.4 /usr/local/mongodb

[root@db02 ~]# vi .bash_profile

PATH=$PATH:/usr/local/mongodb/bin


[root@db02 bin]# mkdir /data/db
[root@db02 bin]# ./mongod
./mongod --help for help and startup options
Tue Apr 3 22:56:29 [initandlisten] MongoDB starting : pid=17303 port=27017 dbpath=/data/db/ 64-bit host=db02
Tue Apr 3 22:56:29 [initandlisten] db version v2.0.4, pdfile version 4.5
Tue Apr 3 22:56:29 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf
Tue Apr 3 22:56:29 [initandlisten] build info: Linux ip-10-110-9-236 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
Tue Apr 3 22:56:29 [initandlisten] options: {}
Tue Apr 3 22:56:29 [initandlisten] journal dir=/data/db/journal
Tue Apr 3 22:56:29 [initandlisten] recover : no journal files present, no recovery needed
Tue Apr 3 22:56:29 [initandlisten] waiting for connections on port 27017
Tue Apr 3 22:56:29 [websvr] admin web console waiting for connections on port 28017


http://ip:28017/

[root@db02 bin]# ./mongostat
connected to: 127.0.0.1
insert query update delete getmore command flushes mapped vsize res faults locked % idx miss % qr|qw ar|aw netIn netOut conn time
0 0 0 0 0 1 0 0m 180m 15m 0 0 0 0|0 0|0 62b 1k 1 23:00:45
0 0 0 0 0 1 0 0m 180m 15m 0 0 0 0|0 0|0 62b 1k 1 23:00:46
0 0 0 0 0 1 0 0m 180m 15m 0 0 0 0|0 0|0 62b 1k 1 23:00:47
0 0 0 0 0 1 0 0m 180m 15m 0 0 0 0|0 0|0 62b 1k 1 23:00:48

[root@db02 bin]# ./mongotop
connected to: 127.0.0.1

ns total read write 2012-04-03T23:00:54
local.system.namespaces 0ms 0ms 0ms
admin.system.users 0ms 0ms 0ms

ns total read write 2012-04-03T23:00:55
local.system.namespaces 0ms 0ms 0ms
admin.system.users 0ms 0ms 0ms

ns total read write 2012-04-03T23:00:56
local.system.namespaces 0ms 0ms 0ms
admin.system.users 0ms 0ms 0ms

[root@db02 bin]#


[root@db02 bin]# ./mongod --rest --nohttpinterface &
[1] 17395
[root@db02 bin]# Tue Apr 3 23:10:12 [initandlisten] MongoDB starting : pid=17395 port=27017 dbpath=/data/db/ 64-bit host=db02
Tue Apr 3 23:10:12 [initandlisten] db version v2.0.4, pdfile version 4.5
Tue Apr 3 23:10:12 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf
Tue Apr 3 23:10:12 [initandlisten] build info: Linux ip-10-110-9-236 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
Tue Apr 3 23:10:12 [initandlisten] options: { nohttpinterface: true, rest: true }
Tue Apr 3 23:10:12 [initandlisten] journal dir=/data/db/journal
Tue Apr 3 23:10:12 [initandlisten] recover : no journal files present, no recovery needed


http://ip:28017/_status


[root@db02 bin]# mongodump -d test -o /data/db/backup
connected to: 127.0.0.1
DATABASE: test to /data/db/backup/test
[root@db02 bin]# mongorestore -d foo --drop /data/db/backup/test
connected to: 127.0.0.1

'db > mongoDB' 카테고리의 다른 글

./mongo  (0) 2012.04.04
posted by 너덜
prev 1 next