Max*_*mov 7 javascript mongodb mongodb-shell
我有js文件mongodb在我得到console.log调试表达式的地方运行:
use test;
db.city.find().snapshot().forEach(function(city){
var Pos = city.Pos;
if (Pos)
{
longLat = Pos.split(" ");
console.log("longLat"); // for debugging ----------------------------
console.log(longLat);
lon = longLat[0];
lat = longLat[1];
if (lon && lat)
{
lon = parseFloat(lon);
lat = parseFloat(lat);
longLat = [lon, lat];
city.longLat = longLat;
}
}
db.orgs.save(city);
})
Run Code Online (Sandbox Code Playgroud)
当我运行它...
mongo < /path/to/this/js/file.js
Run Code Online (Sandbox Code Playgroud)
...输出中出错:
ReferenceError: console is not defined
Run Code Online (Sandbox Code Playgroud)
有没有办法记录中间结果以进行调试?
请改用print或printjson方法.这些用于在shell中发出就像console.log()一样:
if (Pos)
{
longLat = Pos.split(" ");
print("longLat"); // for debugging ----------------------------
printjson(longLat);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3290 次 |
| 最近记录: |