diff --git a/reference/mongo/mongodb/execute.xml b/reference/mongo/mongodb/execute.xml index be4b45788a..67f38c27ca 100644 --- a/reference/mongo/mongodb/execute.xml +++ b/reference/mongo/mongodb/execute.xml @@ -38,6 +38,56 @@ public function execute($code, $args) { ]]> + + MongoDB implies a return statement if you have a single statement on a single + line. This can cause some unintuitive behavior. For example, this returns + "foo": + + +execute('"foo";'); + +?> +]]> + + + However, these return &null;: + + +execute('"bar"; "foo";'); // more than one statement + +$db->execute('db.foo.count( +);'); // more than one line + +?> +]]> + + + To avoid surprising behavior, it is best not to depend on MongoDB to decide + what to return, but to explicitly state a return value. In the examples + above, we can change them to: + + +execute('"bar"; return "foo";'); + +$db->execute('return db.foo.count( +);'); + +?> +]]> + + + Now the first statement will return "foo" and the second statement will + return a count of the "foo" collection. +