At the MongoDB developer zone you can learn all the MongoDB console javascript API to use for document CRUD operations.
I wonder, do all these javascript functions only work on the MongoDB console?
I learn all 开发者_运维技巧that just to use it for administrative tasks or can I use them in my javascript application (node) as well?
Short answer: The functions will only work in the console.
Explanation:
The MongoDB console is a program which happens to accept Javascript. It is a DB client, not a driver. It presents one interface (the console UI) to the user (you), as an abstraction over the database backend (which is the interface presented by the driver).
Applications connect to MongoDB through language-specific drivers, not the console. There is a list of drivers for node.js which will let you connect to the database and perform different tasks. Most, if not all, of the commands you can execute in the console can be done using the drivers, but the syntax will be a little different, as the interface to each driver varies (and the console has its own unique interface too). In the case of Javascript, the syntax is pretty close to that of the console from what I can see (I've never actually used any Javascript drivers).
The console is extremely convenient for quick tests, administrative tasks, etc., so learning it is not wasted. If you know the commands to use MongoDB at the console, then you can easily write application code that accomplishes the same thing using a given driver. It is akin to translating code from one programming language to another (in this case, from the MongoDB-console-Javascript dialect to the node.js-Javascript-with-a-particular-MongoDB-driver dialect).
精彩评论