问题
I am newbie to mongodb (java).
I need to execute list of commands(queries in relational) by using something similar to procedures in relational db.
Is it possible in mongodb?
回答1:
MongoDB has no real sense of stored procedures. It has server side functions however these functions:
- Do not work with sharding
- Are slow
- Must be evaled (Dr. Evil)
- Are only really designed to be used within Map Reduces to stop you from having to house mutiple copies of common code within many places.
However you can achieve it with $where
or eval
ing an actual function name within system.js
. But then these actually don't run "server-side".
Using a exec
type command in your app to call the shell won't be a good idea either. The script files you run in shell are as much client side as your own app so that's just pointless.
MongoDB also does not allow triggers however they are within the JIRA: https://jira.mongodb.org/browse/SERVER-124 but are not scheduled. You will need to place triggers on client side within your coding.
queries in relational
NoSQL is not relational. You might want to read up on how to design a proper schema for MongoDB, here is a starting point: http://www.mongodb.org/display/DOCS/Schema+Design. This will teach you the essence of MongoDB and how to choose the right structure.
回答2:
You can create server-side javascript functions, yes. But I advise against it, because it's will be
- quite slow;
- not version controlled.
Read more: http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-Storingfunctionsserverside
来源:https://stackoverflow.com/questions/12197546/is-procedure-exist-in-mongodb