MongoDB Built function __ function

Source: Internet
Author: User
Tags eval mongodb

To define a function:

Db.system.js.insert ({
        _id: "Testconcat", 
      value:function testconcat (S1, S2) {
                   return s1 + s2
              }
   });

To run the function:

Db.eval (' Testconcat ("abc", "123");


Results:

abc123


The prerequisite is that you must have permission to execute the eval function, as detailed in this article:

http://blog.csdn.net/yabingshi_tech/article/details/47660493


--Note that if you define a function directly using the following similar form, after exiting the session, log in again, call the function, and discover that the function disappears.

Example:

> Function Testconcat (S1, s2) {... return s1 + s2
...               }
> Testconcat (2,3)

5


Exit


> Testconcat (2,3);
2014-02-19t14:11:10.499+0800 Referenceerror:testconcat is not defined


--This article is mainly referred to from: http://blog.csdn.net/miyatang/article/details/19486797,http://www.2cto.com/database/201503/382391.html.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.