{"id":36454132,"url":"https://github.com/boonsuen/objectdb","last_synced_at":"2026-01-11T23:01:06.726Z","repository":{"id":222798136,"uuid":"749864896","full_name":"boonsuen/objectdb","owner":"boonsuen","description":"Embedded document-oriented database for Go.","archived":false,"fork":false,"pushed_at":"2024-02-20T03:19:44.000Z","size":50,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T15:21:37.628Z","etag":null,"topics":["document-database","embedded-database","golang","nosql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/boonsuen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-29T14:54:06.000Z","updated_at":"2024-03-13T14:39:18.000Z","dependencies_parsed_at":"2024-06-21T14:09:02.835Z","dependency_job_id":"29c34508-a34e-496b-861b-4b993bc85f79","html_url":"https://github.com/boonsuen/objectdb","commit_stats":null,"previous_names":["boonsuen/objectdb"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/boonsuen/objectdb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boonsuen%2Fobjectdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boonsuen%2Fobjectdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boonsuen%2Fobjectdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boonsuen%2Fobjectdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boonsuen","download_url":"https://codeload.github.com/boonsuen/objectdb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boonsuen%2Fobjectdb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28326166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T22:11:01.104Z","status":"ssl_error","status_checked_at":"2026-01-11T22:10:58.990Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["document-database","embedded-database","golang","nosql"],"created_at":"2026-01-11T23:01:05.990Z","updated_at":"2026-01-11T23:01:06.713Z","avatar_url":"https://github.com/boonsuen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ObjectDB\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/boonsuen/objectdb.svg)](https://pkg.go.dev/github.com/boonsuen/objectdb)\n[![Go Report Card](https://goreportcard.com/badge/github.com/boonsuen/objectdb)](https://goreportcard.com/report/github.com/boonsuen/objectdb)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nObjectDB is a document-oriented NoSQL database for Go.\n\n## Features\n\n- **Embedded**: No database server required\n- **Document-oriented**: Store and query structs as JSON documents\n- **Tiny**: Simple and lightweight\n\n## Implementation\n\nInternally, ObjectDB uses the [Pebble](https://github.com/cockroachdb/pebble) LSM key-value store as its storage engine.\n\n## Installation\n\n```shell\ngo get github.com/boonsuen/objectdb\n```\n\n## Database and Collection\n\nObjectDB stores documents in collections. A collection is a set of documents. A database can have multiple collections.\n\n### Open a Database\n\n```go\ndb, err := objectdb.Open(\"db\")\nif err != nil {\n  log.Fatal(err)\n  return\n}\ndefer db.Close()\n```\n\n### Insert Documents\n\nCollections are created implicitly when a document is inserted into a collection. Each document is identified by a unique UUID, which is added to the document as the `_id` field.\n\nInsert a document into a collection:\n\n```go\ntype Employee struct {\n  Name string      `json:\"name\"`\n  Age  json.Number `json:\"age\"`\n}\n\nemployee := Employee{\n  Name: \"John\",\n  Age:  \"30\",\n}\n\nid, err := db.InsertOne(\"employees\", employee)\nif err != nil {\n  log.Fatal(err)\n}\n```\n\nInsert multiple documents into a collection:\n\n```go\ntype Address struct {\n  Postcode string `json:\"postcode\"`\n}\n\ntype Restaurant struct {\n  Name    string  `json:\"name\"`\n  Cuisine string  `json:\"cuisine\"`\n  Address Address `json:\"address\"`\n}\n\nnewRestaurants := []Restaurant{\n  {\"Restaurant A\", \"Italian\", Address{\"80000\"}},\n  {\"Restaurant B\", \"Fast Food\", Address{\"10000\"}},\n  {\"Restaurant C\", \"Fast Food\", Address{\"10000\"}},\n  {\"Restaurant D\", \"Fast Food\", Address{\"10000\"}},\n}\n\nids, err := db.InsertMany(\"restaurants\", newRestaurants)\nif err != nil {\n  log.Fatalf(\"error inserting restaurants: %v\", err)\n  return\n} else {\n  log.Printf(\"Inserted restaurants' IDs: %v\", ids)\n}\n\n```\n\n## Queries\n\n### Find a Document\n\nA single document in a collection can be retrieved by using the `FindOne` or `FindOneByID` method. Use the `Unmarshal` method to convert the document to a struct.\n\n```go\ndoc, err := db.FindOneById(\"employees\", id)\nif err != nil {\n  log.Fatal(err)\n}\n\nemployee := Restaurant{}\nerr = objectdb.Unmarshal(doc, \u0026employee)\nif err != nil {\n  log.Fatalf(\"error unmarshalling restaurant: %v\", err)\n  return\n}\n```\n\n`FindOne` returns the first matching document. It's similar to using `FindMany` with a limit of 1.\n\n```go\n// Find one employee with the age of 30\nemployee, err := db.FindOne(\"employees\", objectdb.Query{\n  {\"AND\", []objectdb.Condition{\n    {Path: \"age\", Operator: \"=\", Value: 30},\n  }},\n})\n```\n\n### Find Multiple Documents\n\nTo find multiple matching documents in a collection, use the `FindMany` method.\n\nWith empty query and options, it returns all documents in the collection.\n\n```go\nemployees, err := db.FindMany(\"employees\", objectdb.Query{}, objectdb.Options{})\n```\n\n### Limiting\n\nThe `Options` struct specifies the limit of the number of matching documents to return.\n\n```go\nobjectdb.Options{Limit: 2}\n```\n\n### Filtering\n\nThe `Query` struct specifies the conditions to filter the documents.\n\nThe following example finds 2 Fast Food restaurants with the postcode of 10000.\n\n```go\nresQuery := objectdb.Query{\n  {\"AND\", []objectdb.Condition{\n    {Path: \"cuisine\", Operator: \"=\", Value: \"Fast Food\"},\n    {Path: \"address.postcode\", Operator: \"=\", Value: \"10000\"},\n  }},\n}\n\nffRestaurants, err := db.FindMany(\"restaurants\", resQuery, objectdb.Options{Limit: 2})\n```\n\nThe query accepts multiple conditions. The `AND` and `OR` operators can be used to combine the conditions. Top-level conditions (each element in the `Query` slice) are **implicitly** combined with the `AND` operator. Only two levels of nesting are supported.\n\n```go\nquery := objectdb.Query{\n  {\"AND\", []objectdb.Condition{\n    {Path: \"name\", Operator: \"=\", Value: \"John\"},\n    {Path: \"age\", Operator: \"\u003e=\", Value: \"27\"},\n  }},\n  {\"OR\", []objectdb.Condition{\n    {Path: \"address.city\", Operator: \"=\", Value: \"NY\"},\n    {Path: \"address.postcode\", Operator: \"=\", Value: \"10000\"},\n  }},\n}\n```\n\nQuery above is equivalent to the following SQL where clause:\n\n```sql\nWHERE (name = 'John' AND age \u003e= 27) AND (address.city = 'NY' OR address.postcode = '10000')\n```\n\n## Delete Documents\n\n### Delete a Document\n\nTo delete a document, use the `DeleteOneById` method.\n\n```go\nerr = db.DeleteOneById(\"collectionName\", id)\n```\n\n## Indexing\n\nObjectDB keep tracks of the path-value pairs of the documents in a index. This allows for efficient querying of documents for certain queries. A search will fall back to a full collection scan when it is not possible to solely rely on the index to satisfy the query.\n\n## Full-Text Search\n\nAside from querying using the Find methods, ObjectDB also supports full-text search that scales well with large collections.\n\nTo allow full-text search on a field, annotate the field with the `textIndex` tag. It will be indexed and its text content can be searched in a full-text search query. Note that the field must be of string type.\n\n```go\ntype Restaurant struct {\n  Name    string  `json:\"name\" objectdb:\"textIndex\"`\n  Cuisine string  `json:\"cuisine\" objectdb:\"textIndex\"`\n}\n```\n\nTo perform a full-text search, use the `Search` method.\n\n```go\ndocuments, err := db.Search(\"collectionName\", \"search query\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboonsuen%2Fobjectdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboonsuen%2Fobjectdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboonsuen%2Fobjectdb/lists"}