我的 .js 脚本从包含 mongodb 查询的文件中读取,并将其填充到数组中。然后我读取了该数组并执行了查询,但它们没有被执行。下面是我的代码。
1. //After successfuly connecting to mongodb
2. //read a file containing queries
3. var queryFile = cat("queries.txt");
4. var queries = queryFile.split("\r\n");
5. var length = queries.length;
6. for(var i = 0; i < length; i++){
7. var start = new Date().getTime()
8. queries[i]
9. var end = new Date().getTime();
10. var timeElapsed = (end - start)/1000;
11. print ( "Time taken to run query : "+timeElapsed+" secs" )
12. }
仅当我将第 12 行替换为实际查询时才有效,例如 db.coll.count()