One: Problem description
Sometimes, initialize the data, the number of command bar too much, directly copy INSERT statements, paste into the command line to execute, very slow (time spent on the paste above), so the statements are placed in the JS file execution, more convenient.
However, the first time I executed the JS file today, the error:
[root@ser107 baidandan]# mongo-u root-p--authenticationdatabase admin a.js
MongoDB Shell version:2.6.9
Enter p Assword:
connecting to:test
2015-08-04t16:35:04.913+0800 syntaxerror:unexpected identifier at A.js
Failed to load:a.js
a.js file contents:
[root@ser107 baidandan]# cat a.js use
dba;
Db.a.insert ({name: "Wang", age:20});
Two: The cause of the error
Maybe it's a bug.
The use database name cannot be used in the JS file;
III: Solutions
Remove the use database name in the JS file;
Execute again (specify the database to be manipulated in advance):