[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Firestore in Datastore mode API - Class Google::Cloud::Datastore::Filter (v2.13.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.13.0 (latest)](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-Filter)\n- [2.12.0](/ruby/docs/reference/google-cloud-datastore/2.12.0/Google-Cloud-Datastore-Filter)\n- [2.11.0](/ruby/docs/reference/google-cloud-datastore/2.11.0/Google-Cloud-Datastore-Filter)\n- [2.10.0](/ruby/docs/reference/google-cloud-datastore/2.10.0/Google-Cloud-Datastore-Filter)\n- [2.9.0](/ruby/docs/reference/google-cloud-datastore/2.9.0/Google-Cloud-Datastore-Filter)\n- [2.8.0](/ruby/docs/reference/google-cloud-datastore/2.8.0/Google-Cloud-Datastore-Filter)\n- [2.7.1](/ruby/docs/reference/google-cloud-datastore/2.7.1/Google-Cloud-Datastore-Filter)\n- [2.6.0](/ruby/docs/reference/google-cloud-datastore/2.6.0/Google-Cloud-Datastore-Filter)\n- [2.5.0](/ruby/docs/reference/google-cloud-datastore/2.5.0/Google-Cloud-Datastore-Filter)\n- [2.4.0](/ruby/docs/reference/google-cloud-datastore/2.4.0/Google-Cloud-Datastore-Filter)\n- [2.3.1](/ruby/docs/reference/google-cloud-datastore/2.3.1/Google-Cloud-Datastore-Filter)\n- [2.2.4](/ruby/docs/reference/google-cloud-datastore/2.2.4/Google-Cloud-Datastore-Filter) \nReference documentation and code samples for the Firestore in Datastore mode API class Google::Cloud::Datastore::Filter.\n\nFilter\n\n\n\u003cbr /\u003e\n\nRepresents the filter criteria for a datastore query. \n\nInherits\n--------\n\n- Object\n\nExamples\n--------\n\nRun a query with a simple property filter. \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\nfilter = Google::Cloud::Datastore::Filter.new(\"done\", \"=\", \"false\")\n\nquery = Google::Cloud::Datastore::Query.new\nquery.kind(\"Task\")\n .where(filter)\n\ntasks = datastore.run query\n```\n\nConstruct a composite filter with a logical OR. \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\nfilter = Google::Cloud::Datastore::Filter.new(\"done\", \"=\", \"false\")\n .or(\"priority\", \"\u003e=\", \"4\")\n\nquery = Google::Cloud::Datastore::Query.new\nquery.kind(\"Task\")\n .where(filter)\n\ntasks = datastore.run query\n```\n\nConstruct a composite filter by combining multiple filters. \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\nfilter_1 = Google::Cloud::Datastore::Filter.new(\"done\", \"=\", \"false\")\nfilter_2 = Google::Cloud::Datastore::Filter.new(\"priority\", \"\u003e=\", \"4\")\nfilter = filter_1.or(filter_2)\n\nquery = Google::Cloud::Datastore::Query.new\nquery.kind(\"Task\")\n .where(filter)\n\ntasks = datastore.run query\n```\n\nMethods\n-------\n\n### #and\n\n def and(name, operator, value)\n def and(filter)\n\nJoins two filters with an AND operator. \n**Overloads** \n\n def and(name, operator, value)\n\nJoins the filter with a property filter \n**Parameters**\n\n- **name** (String)\n- **operator** (String)\n- **value** \n\n def and(filter)\n\nJoins the filter with a Filter object \n**Parameter**\n\n- **filter** ([Filter](./Google-Cloud-Datastore-Filter))\n**Examples**\n\nJoin the filter with a property filter \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\nfilter = Google::Cloud::Filter.new(\"done\", \"=\", false)\n .and(\"priority\", \"\u003e=\", 4)\n```\n\nJoin the filter with a filter object \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\nfilter_1 = Google::Cloud::Filter.new(\"done\", \"=\", false)\nfilter_2 = Google::Cloud::Filter.new(\"priority\", \"\u003e=\", 4)\n\nfilter = filter_1.and(filter_2)\n```\n\n### #initialize\n\n def initialize(name, operator, value) -\u003e Filter\n\nCreates a new Filter. \n**Returns**\n\n- ([Filter](./Google-Cloud-Datastore-Filter)) --- a new instance of Filter\n**Example** \n\n```ruby\nrequire \"google/cloud/datastore\"\n\nfilter = Google::Cloud::Datastore::Filter.new(\"done\", \"=\", \"false\")\n```\n\n### #or\n\n def or(name, operator, value)\n def or(filter)\n\nJoins two filters with an OR operator. \n**Overloads** \n\n def or(name, operator, value)\n\nJoins the filter with a property filter \n**Parameters**\n\n- **name** (String) --- The property to filter by.\n- **operator** (String) --- The operator to filter by. Defaults to nil.\n- **value** (Object) ---\n\n The value to compare the property to. Defaults to nil.\n Possible values are:\n - Integer\n - Float/BigDecimal\n - String\n - Boolean\n - Array\n - Date/Time\n - StringIO\n - Google::Cloud::Datastore::Key\n - Google::Cloud::Datastore::Entity\n- nil \n\n def or(filter)\n\nJoins the filter with a Filter object \n**Parameter**\n\n- **flter** ([Filter](./Google-Cloud-Datastore-Filter))\n**Examples**\n\nJoin the filter with a property filter \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\nfilter = Google::Cloud::Filter.new(\"done\", \"=\", false)\n .or(\"priority\", \"\u003e=\", 4)\n```\n\nJoin the filter with a filter object \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\nfilter_1 = Google::Cloud::Filter.new(\"done\", \"=\", false)\nfilter_2 = Google::Cloud::Filter.new(\"priority\", \"\u003e=\", 4)\n\nfilter = filter_1.or(filter_2)\n```"]]