K
K
krll-k2015-07-19 11:30:33
bash
krll-k, 2015-07-19 11:30:33

Are there snippets for the console?

mongodb-client:

[email protected]:~/projects/support$ meteor mongo
MongoDB shell version: 2.6.7
connecting to: 127.0.0.1:3001/meteor
meteor:PRIMARY> show collections
clicks
system.indexes
meteor:PRIMARY> db.clicks.find();
{ "_id" : "cF9dHatA9H8xoLbNJ", "count" : 1 }
meteor:PRIMARY> db.clicks.update({"count":1},{"count":2});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
meteor:PRIMARY> db.clicks.find();
{ "_id" : "cF9dHatA9H8xoLbNJ", "count" : 2 }
meteor:PRIMARY>

I want autocomplete for mongodb methods:
meteor:PRIMARY> meteor:PRIMARY> db.clicks.up[TAB]
meteor:PRIMARY> meteor:PRIMARY> db.clicks.update(query, object[, upsert_bool, multi_bool])

Is it possible to program this using known command shells?
spoiler

mongodb-client collectin methods:
meteor:PRIMARY> db.mycoll.help()
DBCollection help
  db.mycoll.find().help() - show DBCursor help
  db.mycoll.count()
  db.mycoll.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
  db.mycoll.convertToCapped(maxBytes) - calls {convertToCapped:'mycoll', size:maxBytes}} command
  db.mycoll.dataSize()
  db.mycoll.distinct( key ) - e.g. db.mycoll.distinct( 'x' )
  db.mycoll.drop() drop the collection
  db.mycoll.dropIndex(index) - e.g. db.mycoll.dropIndex( "indexName" ) or db.mycoll.dropIndex( { "indexKey" : 1 } )
  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.getPlanCache() get query plan cache associated with collection
  db.mycoll.getIndexes()
  db.mycoll.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
  db.mycoll.insert(obj)
  db.mycoll.mapReduce( mapFunction , reduceFunction , <optional params> )
  db.mycoll.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor
  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]) - instead of two flags, you can pass an object with fields: upsert, multi
  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.mycoll.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function
  db.mycoll.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set
  db.mycoll.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection
  db.mycoll.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection
meteor:PRIMARY> db.help()
DB methods:
  db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [ just calls db.runCommand(...) ]
  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.createUser(userDocument)
  db.currentOp() displays currently executing operations in the db
  db.dropDatabase()
  db.eval(func, args) run code server-side
  db.fsyncLock() flush data to disk and lock server for backups
  db.fsyncUnlock() unlocks server following a db.fsyncLock()
  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 queries on a replication slave server
  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.getWriteConcern() - returns the write concern used for any operations on this db, inherited from server object if set
  db.hostInfo() get details about the server's host
  db.isMaster() check replica primary status
  db.killOp(opid) kills the current operation in the db
  db.listCommands() lists all the db commands
  db.loadServerScripts() loads all the scripts in db.system.js
  db.logout()
  db.printCollectionStats()
  db.printReplicationInfo()
  db.printShardingStatus()
  db.printSlaveReplicationInfo()
  db.dropUser(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.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the db
  db.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the db
  db.setVerboseShell(flag) display extra information in shell output
  db.shutdownServer()
  db.stats()
  db.version() current version of the server
meteor:PRIMARY> db.mycoll.help()
DBCollection help
  db.mycoll.find().help() - show DBCursor help
  db.mycoll.count()
  db.mycoll.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
  db.mycoll.convertToCapped(maxBytes) - calls {convertToCapped:'mycoll', size:maxBytes}} command
  db.mycoll.dataSize()
  db.mycoll.distinct( key ) - e.g. db.mycoll.distinct( 'x' )
  db.mycoll.drop() drop the collection
  db.mycoll.dropIndex(index) - e.g. db.mycoll.dropIndex( "indexName" ) or db.mycoll.dropIndex( { "indexKey" : 1 } )
  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.getPlanCache() get query plan cache associated with collection
  db.mycoll.getIndexes()
  db.mycoll.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
  db.mycoll.insert(obj)
  db.mycoll.mapReduce( mapFunction , reduceFunction , <optional params> )
  db.mycoll.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor
  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]) - instead of two flags, you can pass an object with fields: upsert, multi
  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.mycoll.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function
  db.mycoll.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set
  db.mycoll.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection
  db.mycoll.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection
meteor:PRIMARY>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2015-07-19
@krll-k

when you start the client, the shell rests.
look at robomongo , not cli, but autocomplete is there.

S
sim3x, 2015-07-19
@sim3x

google: mongo bash autocomplete
https://github.com/mongodb/mongo/blob/master/src/t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question