MongoDB Query に特化した .jshintrc を作った

Tadashi Shigeoka ·  Sat, July 29, 2017

MongoDB Query を書くときに JSHint の warning や error が出るのがノイズだったので、MongoDB に特化した .jshintrc を作ったのでご紹介します。

MongoDB | モンゴディービー

MongoDB 用 .jshintrc

MongoDB に特化した .jshintrc が欲しいという方は以下の URL からダウンロードしてください。

MongoDB 用の .jshintrc を作る過程

Mongo shell で使えるメソッドを確認

mongo shell で半角スペース or - とか入れて tab キーをクリックすると、メソッドやクラスなどが全て一覧で表示されます。

Display all 185 possibilities? (y or n)
Array(                       Random(                      create                       isSealed                     run(
BinData(                     RegExp(                      createMongoArgs(             isString(                    runMongoProgram(
Boolean(                     ReplSetBridge(               db                           jsTest                       runProgram(
BulkWriteError(              ReplSetTest(                 decodeURI(                   jsTestFile(                  seal
BulkWriteResult(             ReplTest(                    decodeURIComponent(          jsTestLog(                   setJsTestOption(
CountDownLatch               ShardingTest(                defaultPrompt(               jsTestName(                  setVerboseShell(
DB(                          String(                      defineProperties             jsTestOptions(               sh(
DBCollection(                SyncCCTest(                  defineProperty               jsTestPath(                  shellAutocomplete(
DBCommandCursor(             TestData                     doassert(                    keys                         shellHelper(
DBExplainQuery(              Timestamp(                   encodeURI(                   listFiles(                   shellPrint(
DBPointer(                   ToolTest(                    encodeURIComponent(          load(                        shellPrintHelper(
DBQuery(                     UUID(                        escape(                      ls(                          sleep(
DBRef(                       WriteCommandError(           eval(                        md5sumFile(                  sortDoc(
Date(                        WriteConcern(                false                        mkdir(                       startMongoProgram(
Explainable(                 WriteResult(                 freeze                       module                       startMongoProgramNoConnect(
Geo                          allocatePorts(               friendlyEqual(               myPort(                      startMongod(
HexData(                     argumentsToArray(            gc(                          null                         startMongodEmpty(
ISODate(                     assert(                      getActiveCommands(           parseFloat(                  startMongodNoReset(
Infinity                     authutil                     getBuildInfo(                parseInt(                    startMongodTest(
JSON                         benchFinish(                 getHostName(                 pathExists(                  startMongos(
MD5(                         benchRun(                    getMemInfo(                  preventExtensions            startParallelShell(
MR                           benchRunSync(                getOwnPropertyDescriptor     print(                       stopMongoProgram(
Map(                         benchStart(                  getOwnPropertyNames          printShardingSizes(          stopMongoProgramByPid(
MapReduceResult(             bsonWoCompare(               getPrototypeOf               printShardingStatus(         stopMongod(
Math                         bsonsize                     hasOwnProperty(              printStackTrace(             testingReplication
MaxKey                       cat(                         help(                        printjson(                   toLocaleString(
MinKey                       cd(                          hex_md5(                     printjsononeline(            toString(
Mongo(                       chatty(                      hostname(                    propertyIsEnumerable(        tojson(
MongoRunner(                 checkProgram(                interpreterVersion(          prototype                    tojsonObject(
MongodRunner(                clearRawMongoProgramOutput(  isExtensible                 pwd(                         tojsononeline(
NaN                          compare(                     isFinite(                    quit(                        true
Number(                      compareOn(                   isFrozen                     rawMongoProgramOutput(       undefined
NumberInt(                   connect(                     isKeyTooLarge(               reconnect(                   unescape(
NumberLong(                  connectionURLTheSame(        isMasterStatePrompt(         removeFile(                  validateIndexKey(
ObjectId(                    constructor                  isNaN(                       replSetMemberStatePrompt(    valueOf(
PlanCache(                   copyDbpath(                  isNumber(                    resetDbpath(                 version(
QueryPlan(                   copyFile(                    isObject(                    rs(                          waitProgram(

あと、MongoDB 公式マニュアルでも閲覧できますが shell の出力を整形する方が楽ですね。

矩形選択を使うとサクッと整形できます。一覧は次のとおりです。

Mongo shell のメソッドを JSON 形式に整形する

以下、JSON 形式に整形したメソッド一覧です。

"Array",
"BinData",
"Boolean",
"BulkWriteError",
"BulkWriteResult",
"CountDownLatch",
"DB",
"DBCollection",
"DBCommandCursor",
"DBExplainQuery",
"DBPointer",
"DBQuery",
"DBRef",
"Date",
"Explainable",
"Geo",
"HexData",
"ISODate",
"Infinity",
"JSON",
"MD5",
"MR",
"Map",
"MapReduceResult",
"Math",
"MaxKey",
"MinKey",
"Mongo",
"MongoRunner",
"MongodRunner",
"NaN",
"Number",
"NumberInt",
"NumberLong",
"ObjectId",
"PlanCache",
"QueryPlan",
"Random",
"RegExp",
"ReplSetBridge",
"ReplSetTest",
"ReplTest",
"ShardingTest",
"String",
"SyncCCTest",
"TestData",
"Timestamp",
"ToolTest",
"UUID",
"WriteCommandError",
"WriteConcern",
"WriteResult",
"allocatePorts",
"argumentsToArray",
"assert",
"authutil",
"benchFinish",
"benchRun",
"benchRunSync",
"benchStart",
"bsonWoCompare",
"bsonsize",
"cat",
"cd",
"chatty",
"checkProgram",
"clearRawMongoProgramOutput",
"compare",
"compareOn",
"connect",
"connectionURLTheSame",
"constructor",
"copyDbpath",
"copyFile",
"create",
"createMongoArgs",
"db",
"decodeURI",
"decodeURIComponent",
"defaultPrompt",
"defineProperties",
"defineProperty",
"doassert",
"encodeURI",
"encodeURIComponent",
"escape",
"eval",
"false",
"freeze",
"friendlyEqual",
"gc",
"getActiveCommands",
"getBuildInfo",
"getHostName",
"getMemInfo",
"getOwnPropertyDescriptor",
"getOwnPropertyNames",
"getPrototypeOf",
"hasOwnProperty",
"help",
"hex_md5",
"hostname",
"interpreterVersion",
"isExtensible",
"isFinite",
"isFrozen",
"isKeyTooLarge",
"isMasterStatePrompt",
"isNaN",
"isNumber",
"isObject",
"isSealed",
"isString",
"jsTest",
"jsTestFile",
"jsTestLog",
"jsTestName",
"jsTestOptions",
"jsTestPath",
"keys",
"listFiles",
"load",
"ls",
"md5sumFile",
"mkdir",
"module",
"myPort",
"null",
"parseFloat",
"parseInt",
"pathExists",
"preventExtensions",
"print",
"printShardingSizes",
"printShardingStatus",
"printStackTrace",
"printjson",
"printjsononeline",
"propertyIsEnumerable",
"prototype",
"pwd",
"quit",
"rawMongoProgramOutput",
"reconnect",
"removeFile",
"replSetMemberStatePrompt",
"resetDbpath",
"rs",
"run",
"runMongoProgram",
"runProgram",
"seal",
"setJsTestOption",
"setVerboseShell",
"sh",
"shellAutocomplete",
"shellHelper",
"shellPrint",
"shellPrintHelper",
"sleep",
"sortDoc",
"startMongoProgram",
"startMongoProgramNoConnect",
"startMongod",
"startMongodEmpty",
"startMongodNoReset",
"startMongodTest",
"startMongos",
"startParallelShell",
"stopMongoProgram",
"stopMongoProgramByPid",
"stopMongod",
"testingReplication",
"toLocaleString",
"toString",
"tojson",
"tojsonObject",
"tojsononeline",
"true",
"undefined",
"unescape",
"validateIndexKey",
"valueOf",
"version",
"waitProgram",

MongoDB のクエリを記載した JavaScript ファイルを Git repository で管理するなど、ガッツリ開発するときには .jshintrc があるとクエリ作成が捗るのではないでしょうか。