MongoDB升级至3.6后Pentaho Kettle MongoInput聚合无法获取数据
Hey there, let's work through this issue you're seeing post-MongoDB 3.6 upgrade with Pentaho Kettle's MongoInput step. That error message spells out exactly what's wrong—MongoDB 3.6 introduced a key requirement for aggregate operations, and your Kettle setup isn't meeting it yet.
Why This Happens
Starting in MongoDB 3.6, the aggregate command must include the cursor option (unless you're running an aggregation with the explain argument). Older versions of the Pentaho MongoDB plugin don't send this option by default when running aggregations, which triggers the FailedToParse error (code 9) you encountered:
com.mongodb.MongoCommandException: Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument' on server localhost:2915.完整响应为{ "ok" : 0.0, "errmsg" : "The 'cursor' option is required, except for aggregate with the explain argument", "code" : 9, "codeName" : "FailedToParse" }
Solutions to Try
1. Upgrade the Pentaho MongoDB Plugin
The simplest and most sustainable fix is to update your MongoDB plugin for Pentaho Data Integration (PDI). Newer plugin versions are built to support MongoDB 3.6+ requirements, including automatically adding the cursor option to aggregation queries. Here's how:
- Navigate to your PDI installation folder, then go to
plugins/mongodb - Replace the existing JAR files with the latest compatible versions (make sure they match your PDI version and support MongoDB 3.6)
- Restart PDI, then test your MongoInput aggregation step again.
2. Manually Add the Cursor Option to Your Aggregation Command
If upgrading the plugin isn't feasible right now, you can explicitly add the cursor parameter to your aggregation query. Instead of just passing pipeline stages, structure your full aggregate command like this:
{ "aggregate": "your_collection_name", "pipeline": [ // Paste your existing aggregation stages here (e.g., $match, $group) { "$match": { "status": "active" } }, { "$group": { "_id": "$category", "total": { "$sum": "$amount" } } } ], "cursor": {} }
In the MongoInput step, switch to "Advanced" mode (or the option to input a full command instead of just pipeline stages), then paste this modified command (replace your_collection_name and pipeline stages with your actual data).
3. Verify PDI-MongoDB Compatibility
Double-check that your Pentaho Data Integration version is compatible with MongoDB 3.6. Some older PDI releases might not support newer MongoDB features even with a plugin update. Ensure your PDI version and MongoDB plugin version are designed to work together with MongoDB 3.6.
Quick Tip
After making any changes, test the step with a small dataset first to confirm it's pulling data correctly. If you have other MongoDB-related steps in your Kettle jobs or transformations, update those too to avoid similar compatibility issues.
内容的提问来源于stack exchange,提问作者Elias Gezahegn

