[SERVER-7521] Error is produced to the screen, but command executes anyway. Created: 31/Oct/12  Updated: 15/Feb/13  Resolved: 31/Oct/12

Status: Closed
Project: Core Server
Component/s: Shell, Usability
Affects Version/s: 2.0.7
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: dabest1 Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows XP Professional, Service Pack 3, 32-bit


Operating System: ALL
Participants:

 Description   

An error is shown when attempting to use help() function in the wrong context: "Wed Oct 31 00:38:51 TypeError: d.update(

{'for':"ac3"}

, {$inc:{price:2}}) has no properties (shell):1"
getLastError() returns null and command executes anyway, even though the syntax is not correct for the whole command.

Expected behavior: fail the query if it has incorrect syntax.

Here is an example in mongo shell:
> d
pcat.products
> d.find(

{for: "ac3"}

,

{price:1}

).sort({_id:1}).pretty()

{ "_id" : ObjectId("507d95d5719dbef170f15bf9"), "price" : 21 } { "_id" : ObjectId("507d95d5719dbef170f15bfb"), "price" : 42 } { "_id" : ObjectId("507d95d5719dbef170f15bfc"), "price" : 30.5 } { "_id" : ObjectId("507d95d5719dbef170f15bfd"), "price" : 14 }

> d.update(

{for: "ac3"}

, {$inc: {price: 2}} ).help()
Wed Oct 31 00:38:51 TypeError: d.update(

{'for':"ac3"}

, {$inc:{price:2}}) has no
properties (shell):1
> db.getLastError()
null
> db.getLastErrorObj()
{
"updatedExisting" : true,
"n" : 1,
"connectionId" : 4,
"err" : null,
"ok" : 1
}
> d.find(

{for: "ac3"}

,

{price:1}

).sort({_id:1}).pretty()

{ "_id" : ObjectId("507d95d5719dbef170f15bf9"), "price" : 21 } { "_id" : ObjectId("507d95d5719dbef170f15bfb"), "price" : 42 } { "_id" : ObjectId("507d95d5719dbef170f15bfc"), "price" : 32.5 } { "_id" : ObjectId("507d95d5719dbef170f15bfd"), "price" : 14 }

>



 Comments   
Comment by Scott Hernandez (Inactive) [ 31/Oct/12 ]

The error you are seeing is due to you acting on the result of the update operation on the client (in javascript), not a server command or operation.

Since the (javascript) shell allows you to run arbitrary javascript code the shell is not able to verify every line before fully executing it; this is how the javascript interpreter works and is normal behavior.

Generated at Thu Feb 08 03:14:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.