mongo shell script won't let me include “use

前端 未结 3 1579
失恋的感觉
失恋的感觉 2020-12-25 12:26

32-bit mongo 2.0.1 on a windows XP machine

//script filename: test.js  (one line shell script file to store a person)
db.cTest.save({Name: \"Fred\", Age:21})         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-25 12:57

    Well, it still is unfortunate that "load('file.js')" and "mongo file.js" don't actually use the same script interpreter as the interactive mongo shell. Opening the connection explicitly in the script is potentially a violation of the DRY principle because mongo already knows that information. What does work, though, is piping the file into mongo rather than passing its name on the command line:

    mongo 

提交回复
热议问题