<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-86  評論-33  文章-0  trackbacks-0

    Command Line

    --help

    Show command line options

    --nodb

    Start without a db, you can connect later with new Mongo() or connect()

    --shell

    After running a .js file from the command line, stay in the shell rather than terminating

    Special Command Helpers

    Non-javascript convenience macros:

    help

    Show help

    db.help()

    Show help on db methods

    db.myColl.help()

    Show help on collection methods

    show dbs

    Print a list of all databases on this server

    use dbname

    Set the db variable to represent usage of dbname on the server

    show collections

    Print a list of all collections for current database

    show users

    Print a list of users for current database

    show profile

    Print most recent profiling operations that took >= 1ms

    Basic Shell Javascript Operations

    db

    The variable that references the current database object / connection. Already defined for you in your instance.

    db.auth(user,pass)

    Authenticate with the database (if running in secure mode).

    coll = db.collection

    Access a specific collection within the database.

    cursor = coll.find();

    Find all objects in the collection. See queries.

    coll.remove(objpattern);

    Remove matching objects from the collection. 
    objpattern is an object specifying fields to match. E.g.: coll.remove( { name: "Joe" } );

    coll.save(object)

    Save an object in the collection, or update if already there. 
    If your object has a presave method, that method will be called before the object is saved to the db (before both updates and inserts)

    coll.insert(object) 

    Insert object in collection.  No check is made (i.e., no upsert) that the object is not already present in the collection. 

    coll.update(...) 

    Update an object in a collection.  See the Updating documentation; update() has many options. 

    coll.ensureIndex( { name: 1 } )

    Creates an index on tab.name. Does nothing if index already exists.

    coll.update(...)

     

    coll.drop()

    Drops the collection coll

    db.getSisterDB(name)

    Return a reference to another database using this same connection. Usage example:db.getSisterDB('production').getCollectionNames()

    Queries

    coll.find()

    Find all.

    it

    Continue iterating the last cursor returned from find().

    coll.find(criteria );

    Find objects matching criteria in the collection. E.g.: coll.find( { name: "Joe" } );

    coll.findOne(criteria );

    Find and return a single object. Returns null if not found. If you want only one object returned, this is more efficient than just find() as limit(1) is implied. You may use regular expressions if the element type is a string, number, or date: coll.find( { name: /joe/i } );

    coll.find( criteria, fields );

    Get just specific fields from the object. E.g.: coll.find( {}, {name:true} );

    coll.find().sort( {field:1[,field:1] });

    Return results in the specified order (field ASC). Use -1 for DESC.

    coll.find(criteria ).sort( { field : 1 } )

    Return the objects matching criteria, sorted by field.

    coll.find( ... ).limit(n)

    Limit result to n rows. Highly recommended if you need only a certain number of rows for best performance.

    coll.find( ... ).skip(n )

    Skip n results.

    coll.count()

    Returns total number of objects in the collection.

    coll.find( ... ).count()

    Returns the total number of objects that match the query. Note that the number ignores limit and skip; for example if 100 records match but the limit is 10, count() will return 100. This will be faster than iterating yourself, but still take time.

    More information: see queries.

    Error Checking

    db.getLastError()

    Returns error from the last operation.

    db.getPrevError()

    Returns error from previous operations.

    db.resetError()

    Clear error memory.

    Administrative Command Helpers

    db.cloneDatabase(fromhost)

    Clone the current database from the other host specified. fromhost database must be in noauth mode.

    db.copyDatabase(fromdb, todb, fromhost)

    Copy fromhost/fromdb to todb on this server. fromhost must be in noauth mode.

    db.repairDatabase()

    Repair and compact the current database. This operation can be very slow on large databases.

    db.addUser(user,pwd)

    Add user to current database.

    db.getCollectionNames()

    get list of all collections.

    db.dropDatabase()

    Drops the current database.

    Opening Additional Connections

    db = connect("<host>:<port>/<dbname>")

    Open a new database connection. One may have multiple connections within a single shell, however, automatic getLastError reporting by the shell is done for the 'db' variable only. See here for an example of connect().

    conn = new Mongo("hostname")

    Open a connection to a new server. Use getDB() to select a database thereafter.

    db = conn.getDB("dbname")

    Select a specific database for a connection

    Miscellaneous

    Object.bsonsize(db.foo.findOne())

    prints the bson size of a db object (mongo version 1.3 and greater)

    db.foo.findOne().bsonsize()

    prints the bson size of a db object (mongo versions predating 1.3)

     

    posted on 2010-07-05 11:15 Derek.Guo 閱讀(545) 評論(0)  編輯  收藏 所屬分類: NoSqlDB

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    MSN:envoydada@hotmail.com QQ:34935442
    主站蜘蛛池模板: 免费国产成人高清在线观看网站| 国产羞羞的视频在线观看免费 | 一个人看的www免费高清| 国产1024精品视频专区免费| 亚洲成a人片毛片在线| 最近中文字幕完整版免费高清| 亚洲色偷偷偷网站色偷一区| 国产四虎免费精品视频| 亚洲www77777| 四虎AV永久在线精品免费观看| 特级毛片全部免费播放a一级| 亚洲国产午夜福利在线播放| xxxxx做受大片视频免费| 亚洲国产精品嫩草影院在线观看 | 亚洲综合国产成人丁香五月激情| 无码少妇一区二区浪潮免费| 亚洲av色香蕉一区二区三区 | 在线观看免费大黄网站| 国产亚洲福利精品一区二区| 狠狠亚洲狠狠欧洲2019| 久久狠狠躁免费观看2020| 亚洲第一网站免费视频| 免费人成视频在线| 国产亚洲女在线线精品| 亚洲国产精品无码一线岛国| 美女裸身网站免费看免费网站| 亚洲AV无码精品国产成人| 国产亚洲成人久久| 久久久久av无码免费网 | 久久亚洲中文无码咪咪爱| 亚洲精品国产高清不卡在线 | 成人免费AA片在线观看| 国产亚洲精品成人久久网站| 亚洲国产精品成人精品无码区在线| 狼群影院在线观看免费观看直播| 亚洲成熟丰满熟妇高潮XXXXX| 国产成人精品久久亚洲| 亚洲啪啪免费视频| 一区二区三区视频免费观看| 亚洲精品免费在线视频| 亚洲第一成人影院|