Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 中止mongoshell命令(作为无限循环),而不结束shell本身_Mongodb_Mongodb Shell - Fatal编程技术网

Mongodb 中止mongoshell命令(作为无限循环),而不结束shell本身

Mongodb 中止mongoshell命令(作为无限循环),而不结束shell本身,mongodb,mongodb-shell,Mongodb,Mongodb Shell,我在MongoDB shell 4.2版中运行以下内容作为参考: while(true) { db.c.update({_id:1}, {$inc: {n: 1}}) } 我想打破while循环,但不结束MongoDB shell。如果我使用Ctrl+C,循环结束,mongo进程也会结束,就像我退出一样 查看时,我发现Ctrl+G作为abort,但它不起作用,似乎什么也没做 有可能做我正在尝试的事情吗?Ctrl+G的作用是什么 谢谢 不可能。您将中止MongoDB操作与JS执行混为一谈 Ctr

我在MongoDB shell 4.2版中运行以下内容作为参考:

while(true) { db.c.update({_id:1}, {$inc: {n: 1}}) }
我想打破while循环,但不结束MongoDB shell。如果我使用Ctrl+C,循环结束,mongo进程也会结束,就像我退出一样

查看时,我发现Ctrl+G作为abort,但它不起作用,似乎什么也没做

有可能做我正在尝试的事情吗?Ctrl+G的作用是什么


谢谢

不可能。您将中止MongoDB操作与JS执行混为一谈

Ctrl+G中止单个CRUD操作,而不是在{…}

让我们看看这个例子:

db.collection.find({$where:"this.foo==1"});print("1");db.collection.find({$where:"this.foo==1"});print("2");
> executing...
> Ctrl + G
> 1
> executing...
> Ctrl + G
> 2

不可能。您将中止MongoDB操作与JS执行混为一谈

Ctrl+G中止单个CRUD操作,而不是在{…}

让我们看看这个例子:

db.collection.find({$where:"this.foo==1"});print("1");db.collection.find({$where:"this.foo==1"});print("2");
> executing...
> Ctrl + G
> 1
> executing...
> Ctrl + G
> 2

我们不应该将JS执行与中止shell混淆

要中止MongoDB shell中的JS查询,请查看以下线程:

在编程方面,您可以使用break引起JS循环中断,而不会影响shell

例如,每2秒重复10次你的狙击手,你可以这样做

var i=1; whiletrue{ db.c.update{{u id:1},{$inc:{n:1}; ifi>10{ 打破 } 睡眠2000年; i++;
} 我们不应该将JS执行与中止shell混淆

要中止MongoDB shell中的JS查询,请查看以下线程:

在编程方面,您可以使用break引起JS循环中断,而不会影响shell

例如,每2秒重复10次你的狙击手,你可以这样做

var i=1; whiletrue{ db.c.update{{u id:1},{$inc:{n:1}; ifi>10{ 打破 } 睡眠2000年; i++; }