update : 2015.11.03
php.shukuma.com검색:
|
MongoDB::execute(PECL mongo >=0.9.3) MongoDB::execute — Runs JavaScript code on the database server [deprecated] 설명Warning
The » eval command, which this method invokes, is deprecated in MongoDB 3.0+. The Mongo database server runs a JavaScript engine. This method allows you to run arbitary JavaScript on the database. This can be useful if you want touch a number of collections lightly, or process some results on the database side to reduce the amount that has to be sent to the client. Running JavaScript in the database takes a write lock, meaning it blocks other operations. Make sure you consider this before running a long script. This is a wrapper for the » eval database command. This method is basically:
<?php 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":
<?php
However, these return
<?php 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:
<?php Now the first statement will return "foo" and the second statement will return a count of the "foo" collection. 반환값Returns the result of the evaluation. 예제Example #1 Simple MongoDB::execute() example
<?php 위 예제의 출력 예시: Hello, world! Example #2 Parameter MongoDB::execute() example The optional array of parameters will be passed to the JavaScript function.
<?php 위 예제의 출력 예시: Good bye, Joe! Example #3 Scope example If a MongoCode object is used instead of a string for the first parameter, a scope can be passed in which the JavaScript will be executed.
<?php 위 예제의 출력 예시: Goodbye, Joe, says Fred 참고
변경점
|