0

I've read that aggregation framework relies on "pipeline" architecture, i.e.

db.myCollection.aggregate({
  $op1: { ... }
},{
  $op2: { ... }
})

On the other hand, the "traditional" mongo command-line query syntax is also pipeline-like:

db.myCollection.find({
  field: 'value'
}).filter({
  ...
}).forEach({
  ...
})
  1. Is there any difference in the implementation under the hood?
  2. The "traditional" syntax is also kinda pipeline-like - why the alternative syntax exist at all?

1 Answer 1

3

Is there any difference in the implementation under the hood?

Lots. For example the first one runs "within" MongoDB in its C++ code as the aggregation framework while the other one runs within a V8/spidermonkey (depending on your version) environment within the bundled JS console.

It is most likely good to mention that the latter syntax you show does not run "within" MongoDB but rather a JS console that has capabilities to interact with MongoDB via a JS driver.

This applies to most databases such as the MySQL console and many others. They are just bundled client side programs.

The "traditional" syntax is also kinda pipeline-like - why the alternative syntax exist at all?

Because the console is not MongoDB.

Sign up to request clarification or add additional context in comments.

2 Comments

Few questions to make it crystal clear please: (1) The javascript interface is pure syntax and (even sharing a pipeline feel) has nothing to do with MongoDB internal implementation. (2) Aggregate framework utilizes a special optimised pipeline implementation on MongoDB server-side. Am I right about the two above? And if so, why re-introduce a different syntax rather than binding the same old syntax to the better implementation?
@BreakPhreak About the points exactly and about the different syntax, it is because this needs to be called from client side and code would need to be evaled which is terrible way of implementation, plus having a SQL type structure like this allows use of indexes etc which MR cannot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.