{
  "id": "mongodb/aggregation-lookup-views-not-supported",
  "signature": "MongoServerError: $lookup with 'from' referencing a view is not supported in this version",
  "signature_zh": "MongoServerError: 此版本不支持 $lookup 中 'from' 引用视图",
  "regex": "\\$lookup with 'from' referencing a view is not supported in this version",
  "domain": "mongodb",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The aggregation pipeline uses $lookup to join with a view, which is not allowed in MongoDB versions prior to 5.0 or in certain configurations.",
  "root_cause_type": "generic",
  "root_cause_zh": "聚合管道使用 $lookup 连接视图，这在 MongoDB 5.0 之前的版本或某些配置中不被允许。",
  "versions": [
    {
      "version": "MongoDB 4.4",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MongoDB 5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MongoDB 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Even in supported versions, $lookup on views has limitations (e.g., no $lookup on sharded views).",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Indexes on views are not supported; the underlying collection must be indexed.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error is about referencing a view, not about the syntax used.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Replace the $lookup on a view with a $lookup on the underlying collection, then filter using $match: db.orders.aggregate([ { $lookup: { from: \"products\", localField: \"productId\", foreignField: \"_id\", as: \"product\" } }, { $match: { \"product.price\": { $gt: 100 } } } ])",
      "success_rate": 0.9,
      "how": "Replace the $lookup on a view with a $lookup on the underlying collection, then filter using $match: db.orders.aggregate([ { $lookup: { from: \"products\", localField: \"productId\", foreignField: \"_id\", as: \"product\" } }, { $match: { \"product.price\": { $gt: 100 } } } ])",
      "condition": "",
      "sources": []
    },
    {
      "action": "Materialize the view as a real collection using $merge: db.sourceCollection.aggregate([ { $match: ... }, { $merge: { into: \"materializedView\" } } ]); then use $lookup on the materialized collection.",
      "success_rate": 0.85,
      "how": "Materialize the view as a real collection using $merge: db.sourceCollection.aggregate([ { $match: ... }, { $merge: { into: \"materializedView\" } } ]); then use $lookup on the materialized collection.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using MongoDB 5.0+, ensure the feature flag for views in $lookup is enabled by checking the version and using the correct syntax: db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })",
      "success_rate": 0.8,
      "how": "If using MongoDB 5.0+, ensure the feature flag for views in $lookup is enabled by checking the version and using the correct syntax: db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Replace the $lookup on a view with a $lookup on the underlying collection, then filter using $match: db.orders.aggregate([ { $lookup: { from: \"products\", localField: \"productId\", foreignField: \"_id\", as: \"product\" } }, { $match: { \"product.price\": { $gt: 100 } } } ])",
    "Materialize the view as a real collection using $merge: db.sourceCollection.aggregate([ { $match: ... }, { $merge: { into: \"materializedView\" } } ]); then use $lookup on the materialized collection.",
    "If using MongoDB 5.0+, ensure the feature flag for views in $lookup is enabled by checking the version and using the correct syntax: db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.81,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-06-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}