{"record":{"id":"f373ee6ab6d0ce6a","repo":"gatsbyjs/gatsby","slug":"the-nin-operator-expects-an-array-as-value","errorCode":null,"errorMessage":"The $nin operator expects an array as value","messagePattern":"The \\$nin operator expects an array as value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/datastore/in-memory/indexing.ts","lineNumber":746,"sourceCode":"        // This will also dedupe so don't do that immediately\n        return unionNodesByCounter(nodes, arr)\n      }\n    }\n\n    // elemMatch can cause a node to appear in multiple buckets so we must dedupe first\n    if (wasElemMatch) {\n      expensiveDedupeInline(arr)\n    }\n\n    return arr\n  }\n\n  if (op === `$nin`) {\n    // This is essentially the same as the $ne operator, just with multiple\n    // values to exclude.\n\n    if (!Array.isArray(filterValue)) {\n      throw new Error(`The $nin operator expects an array as value`)\n    }\n\n    const values: Set<FilterValueNullable> = new Set(filterValue)\n    const set = new Set(filterCache.meta.nodesUnordered)\n\n    // Do the action for \"$ne\" for each element in the set of values\n    values.forEach(filterValue => {\n      removeBucketFromSet(filterValue, filterCache, set)\n    })\n\n    // TODO: there's probably a more efficient algorithm to do set\n    //       subtraction in such a way that we don't have to re-sort\n    return [...set].sort(sortByIds)\n  }\n\n  if (op === `$ne`) {\n    const set = new Set(filterCache.meta.nodesUnordered)\n","sourceCodeStart":728,"sourceCodeEnd":764,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/datastore/in-memory/indexing.ts#L728-L764","documentation":"`$nin` (negated membership, `filter: { field: { nin: [...] } }`) mirrors `$in`: its value must be an Array so the runner can build a set of values to exclude. A non-array is rejected up front.","triggerScenarios":"`filter: { status: { nin: \"draft\" } }` or a non-array variable.","commonSituations":"Same as `$in`: scalar passed instead of list; mistyped GraphQL variable.","solutions":["Wrap the value in an array: `nin: [\"draft\"]`.","Use a list GraphQL variable type.","If you meant a single exclude, consider `$ne` instead."],"exampleFix":"// before\nfilter: { status: { nin: \"draft\" } }\n// after\nfilter: { status: { nin: [\"draft\"] } }","handlingStrategy":"type-guard","validationCode":"function asArray<T>(v: T | T[]): T[] { return Array.isArray(v) ? v : [v] }\n// filter: { status: { nin: asArray(excluded) } }\n","typeGuard":"function isNinFilterValue(v: unknown): v is unknown[] { return Array.isArray(v) }\n","tryCatchPattern":null,"preventionTips":["Type GraphQL variables for `nin` as `[Type]!`.","Use `$ne` when excluding a single value."],"tags":["graphql","query","filter","datastore"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}