is procedure exist in mongodb

2019-09-11 19:41发布

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?

2条回答
Melony?
2楼-- · 2019-09-11 20:06

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 evaling 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.

查看更多
孤傲高冷的网名
3楼-- · 2019-09-11 20:09

You can create server-side javascript functions, yes. But I advise against it, because it's will be

  1. quite slow;
  2. not version controlled.

Read more: http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-Storingfunctionsserverside

查看更多
登录 后发表回答