锘??xml version="1.0" encoding="utf-8" standalone="yes"?>aaa亚洲精品,久久精品伊人,国产综合亚洲精品一区二http://www.aygfsteel.com/envoydada/category/45571.htmlzh-cnTue, 13 Jul 2010 03:23:48 GMTTue, 13 Jul 2010 03:23:48 GMT60Mongodb Import Export Toolshttp://www.aygfsteel.com/envoydada/archive/2010/07/05/325305.htmlDerek.GuoDerek.GuoMon, 05 Jul 2010 09:52:00 GMThttp://www.aygfsteel.com/envoydada/archive/2010/07/05/325305.htmlhttp://www.aygfsteel.com/envoydada/comments/325305.htmlhttp://www.aygfsteel.com/envoydada/archive/2010/07/05/325305.html#Feedback0http://www.aygfsteel.com/envoydada/comments/commentRss/325305.htmlhttp://www.aygfsteel.com/envoydada/services/trackbacks/325305.html

Import Export Tools

These tool just work with the raw data (the documents in the collection); they do not save, or load, the metadata like the defined indexes or (capped) collection properties. You will need to (re)create those yourself in a separate step, before loading that data. Vote here to change this.

mongoimport

This utility takes a single file that contains 1 JSON/CSV/TSV string per line and inserts it. You have to specify a database and a collection.

options:
            --help                  produce help message
            -v [ --verbose ]        be more verbose (include multiple times for more
            			    verbosity e.g. -vvvvv)
            -h [ --host ] arg       mongo host to connect to ("left,right" for pairs)
            -d [ --db ] arg         database to use
            -c [ --collection ] arg collection to use (some commands)
            -u [ --username ] arg   username
            -p [ --password ] arg   password
            --dbpath arg            directly access mongod data files in the given path,
            			    instead of connecting to a mongod instance - needs to
            			    lock the data directory, so cannot be used if a
            			    mongod is currently accessing the same path
            --directoryperdb        if dbpath specified, each db is in a separate
            directory
            -f [ --fields ] arg     comma seperated list of field names e.g. -f name,age
            --fieldFile arg         file with fields names - 1 per line
            --ignoreBlanks          if given, empty fields in csv and tsv will be ignored
            --type arg              type of file to import.  default: json (json,csv,tsv)
            --file arg              file to import from; if not specified stdin is used
            --drop                  drop collection first
            --headerline            CSV,TSV only - use first line as headers
            

mongoexport

This utility takes a collection and exports to either JSON or CSV. You can specify a filter for the query, or a list of fields to output.

Neither JSON nor TSV/CSV can represent all data types. Please be careful not to lose or change data (types) when using this. For full fidelity please use mongodump.

If you want to output CSV, you have to specify the fields in the order you want them.

Example

options:
            --help                  produce help message
            -v [ --verbose ]        be more verbose (include multiple times for more
            			    verbosity e.g. -vvvvv)
            -h [ --host ] arg       mongo host to connect to ("left,right" for pairs)
            -d [ --db ] arg         database to use
            -c [ --collection ] arg collection to use (some commands)
            -u [ --username ] arg   username
            -p [ --password ] arg   password
            --dbpath arg            directly access mongod data files in the given path,
            			    instead of connecting to a mongod instance - needs to
            			    lock the data directory, so cannot be used if a
            			    mongod is currently accessing the same path
            --directoryperdb        if dbpath specified, each db is in a separate
            directory
            -q [ --query ] arg      query filter, as a JSON string
            -f [ --fields ] arg     comma seperated list of field names e.g. -f name,age
            --csv                   export to csv instead of json
            -o [ --out ] arg        output file; if not specified, stdout is used
            

mongodump

This takes a database and outputs it in a binary representation. This is mostly used for doing hot backups of a database.

If you're using sharding and try to migrate data this way, this will dump shard configuration information and overwrite configurations upon restore.
options:
            --help                   produce help message
            -v [ --verbose ]         be more verbose (include multiple times for more
            			     verbosity e.g. -vvvvv)
            -h [ --host ] arg        mongo host to connect to ("left,right" for pairs)
            -d [ --db ] arg          database to use
            -c [ --collection ] arg  collection to use (some commands)
            -u [ --username ] arg    username
            -p [ --password ] arg    password
            --dbpath arg             directly access mongod data files in the given path,
            			     instead of connecting to a mongod instance - needs
            			     to lock the data directory, so cannot be used if a
            				     mongod is currently accessing the same path
            --directoryperdb         if dbpath specified, each db is in a separate
            directory
            -o [ --out ] arg (=dump) output directory
            

Example: Dumping Everything

To dump all of the collections in all of the databases, run mongodump with just the --host:

$ ./mongodump --host prod.example.com
            connected to: prod.example.com
            all dbs
            DATABASE: log    to   dump/log
            log.errors to dump/log/errors.bson
            713 objects
            log.analytics to dump/log/analytics.bson
            234810 objects
            DATABASE: blog    to    dump/blog
            blog.posts to dump/log/blog.posts.bson
            59 objects
            DATABASE: admin    to    dump/admin
            

You'll then have a folder called "dump" in your current directory.

If you're running mongod locally on the default port, you can just do:

$ ./mongodump
            

Example: Dumping a Single Collection

If we just want to dump a single collection, we can specify it and get a single .bson file.

$ ./mongodump --db blog --collection posts
            connected to: 127.0.0.1
            DATABASE: blog        to     dump/blog
            blog.posts to dump/blog/posts.bson
            59 objects
            

mongorestore

This takes the output from mongodump and restores it.

usage: ./mongorestore [options] [directory or filename to restore from]
            options:
            --help                  produce help message
            -v [ --verbose ]        be more verbose (include multiple times for more
            			    verbosity e.g. -vvvvv)
            -h [ --host ] arg       mongo host to connect to ("left,right" for pairs)
            -d [ --db ] arg         database to use
            -c [ --collection ] arg collection to use (some commands)
            -u [ --username ] arg   username
            -p [ --password ] arg   password
            --dbpath arg            directly access mongod data files in the given path,
            				    instead of connecting to a mongod instance - needs to
            				    lock the data directory, so cannot be used if a
            			    mongod is currently accessing the same path
            --directoryperdb        if dbpath specified, each db is in a separate
            directory
            --drop                  drop each collection before import
            --objcheck              validate object before inserting


Derek.Guo 2010-07-05 17:52 鍙戣〃璇勮
]]>
Mongodb dbshell Referencehttp://www.aygfsteel.com/envoydada/archive/2010/07/05/325266.htmlDerek.GuoDerek.GuoMon, 05 Jul 2010 03:15:00 GMThttp://www.aygfsteel.com/envoydada/archive/2010/07/05/325266.htmlhttp://www.aygfsteel.com/envoydada/comments/325266.htmlhttp://www.aygfsteel.com/envoydada/archive/2010/07/05/325266.html#Feedback0http://www.aygfsteel.com/envoydada/comments/commentRss/325266.htmlhttp://www.aygfsteel.com/envoydada/services/trackbacks/325266.html闃呰鍏ㄦ枃

Derek.Guo 2010-07-05 11:15 鍙戣〃璇勮
]]>
杞琺ongodb鍏ラ棬http://www.aygfsteel.com/envoydada/archive/2010/06/23/324266.htmlDerek.GuoDerek.GuoWed, 23 Jun 2010 07:40:00 GMThttp://www.aygfsteel.com/envoydada/archive/2010/06/23/324266.htmlhttp://www.aygfsteel.com/envoydada/comments/324266.htmlhttp://www.aygfsteel.com/envoydada/archive/2010/06/23/324266.html#Feedback0http://www.aygfsteel.com/envoydada/comments/commentRss/324266.htmlhttp://www.aygfsteel.com/envoydada/services/trackbacks/324266.html闃呰鍏ㄦ枃

Derek.Guo 2010-06-23 15:40 鍙戣〃璇勮
]]>
Mongodb Dynamic querys selecthttp://www.aygfsteel.com/envoydada/archive/2010/06/23/324255.htmlDerek.GuoDerek.GuoWed, 23 Jun 2010 06:13:00 GMThttp://www.aygfsteel.com/envoydada/archive/2010/06/23/324255.htmlhttp://www.aygfsteel.com/envoydada/comments/324255.htmlhttp://www.aygfsteel.com/envoydada/archive/2010/06/23/324255.html#Feedback0http://www.aygfsteel.com/envoydada/comments/commentRss/324255.htmlhttp://www.aygfsteel.com/envoydada/services/trackbacks/324255.htmlMySQL:
    
SELECT * FROM user
Mongo:    
    db.
user.find()


MySQL:
    
SELECT * FROM user WHERE name = 'foobar'
Mongo:    
    db.
user.find({'name' : 'foobar'})


MySQL:
    
INSERT INOT user (`name`, `age`) values ('foobar',25)
Mongo:    
   db.
user.insert({'name' : 'foobar''age' : 25})


if you want add a  column `email` on MySQL,you must :
   
ALTER TABLE user….
But 
in Mongo,you can just:    
  db.
user.insert({'name' : 'foobar''age' : 25'email' : 'foo@bar.com'})


MySQL:
    
DELETE * FROM user
Mongo:    
    db.
user.remove({})


MySQL:
    
DELETE FROM user WHERE age < 30
Mongo:    
    db.
user.remove({'age' : {$lt : 30}})

$gt : 
> ; $gte : >= ; $lt : < ; $lte : <= ; $ne : !=


MySQL:
    
UPDATE user SET `age` = 36 WHERE `name` = 'foobar'
Mongo:    
    db.
user.update({'name' : 'foobar'}, {$set : {'age' : 36}})


MySQL:
    
UPDATE user SET `age` = `age` + 3 WHERE `name` = 'foobar'
Mongo:    
   db.
user.update({'name' : 'foobar'}, {$inc : {'age' : 3}})

        See more @ http:
//www.mongodb.org/display/DOCS/Updating


MySQL:
    
SELECT COUNT(*FROM user WHERE `name` = 'foobar'
Mongo:    
    db.
user.find({'name' : 'foobar'}).count() 鎴?db.user.count({name:'foobar'});


MySQL:
    
SELECT * FROM user limit 10,20
Mongo:    
   db.
user.find().skip(10).limit(20)


MySQL:
    
SELECT * FROM user WHERE `age` IN (2535,45)
Mongo:    
    db.
user.find({'age' : {$in : [25, 35, 45]}})


MySQL:
    
SELECT * FROM user ORDER BY age DESC
Mongo:    
    db.
user.find().sort({'age' : -1})


MySQL:
    
SELECT DISTINCT(name) FROM user WHERE age > 20
Mongo:    
   db.
user.distinct('name', {'age': {$lt : 20}})


MySQL:
    
SELECT name, sum(marks) FROM user GROUP BY name
Mongo:    
    db.
user.group({
        
key : {'name' : true},
        cond: {
'name' : 'foo'},
        reduce: 
function(obj,prev) { prev.msum += obj.marks; },
        initial: {msum : 
0}
    });


MySQL:
    
SELECT name FROM user WHERE age < 20
Mongo:    
   db.
user.find('this.age < 20', {name : 1})

Derek.Guo 2010-06-23 14:13 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 蓝田县| 遵化市| 比如县| 斗六市| 微山县| 新和县| 邯郸县| 东光县| 彭水| 特克斯县| 湟源县| 遵义县| 光山县| 娄烦县| 包头市| 绿春县| 西乌珠穆沁旗| 平度市| 凤山市| 玉溪市| 通化市| 札达县| 宜春市| 通渭县| 乐平市| 墨竹工卡县| 荥阳市| 两当县| 景宁| 虞城县| 桂阳县| 田林县| 天峨县| 高要市| 宁远县| 金山区| 陵川县| 曲麻莱县| 华亭县| 威信县| 天门市|