<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vinícius Santos</title>
    <description>The latest articles on DEV Community by Vinícius Santos (@vfssantos).</description>
    <link>https://dev.to/vfssantos</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2936042%2Fe285ace5-45d8-4427-8bd7-24f3b0932d8f.png</url>
      <title>DEV Community: Vinícius Santos</title>
      <link>https://dev.to/vfssantos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vfssantos"/>
    <language>en</language>
    <item>
      <title>Introducing Dengo: MongoDB API for Deno KV</title>
      <dc:creator>Vinícius Santos</dc:creator>
      <pubDate>Wed, 12 Mar 2025 14:47:58 +0000</pubDate>
      <link>https://dev.to/vfssantos/introducing-dengo-mongodb-api-for-deno-kv-4cgf</link>
      <guid>https://dev.to/vfssantos/introducing-dengo-mongodb-api-for-deno-kv-4cgf</guid>
      <description>&lt;h2&gt;
  
  
  The Best of Both Worlds: MongoDB's Familiar API with Deno's Native KV Store
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8p7sg9ls50o8eqrd583.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8p7sg9ls50o8eqrd583.png" alt="Dengo - MongoDB API for Deno KV" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today, I'm excited to introduce &lt;strong&gt;Dengo&lt;/strong&gt;, a MongoDB-compatible database layer&lt;br&gt;
for Deno KV. Dengo brings the familiar MongoDB API to Deno's built-in key-value&lt;br&gt;
store, allowing developers to leverage MongoDB's powerful query capabilities&lt;br&gt;
while enjoying the simplicity and performance of Deno KV.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Dengo?
&lt;/h2&gt;

&lt;p&gt;When building applications with Deno, especially for edge deployments, you often&lt;br&gt;
need a database solution that is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Lightweight&lt;/strong&gt; - No heavy dependencies or external services&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Familiar&lt;/strong&gt; - Minimal learning curve for your team&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type-safe&lt;/strong&gt; - First-class TypeScript support&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Serverless-ready&lt;/strong&gt; - Works seamlessly in edge functions&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Deno's built-in KV store is perfect for edge deployments, but its API is quite&lt;br&gt;
different from traditional document databases like MongoDB. This is where Dengo&lt;br&gt;
comes in - it bridges this gap by providing a MongoDB-compatible API on top of&lt;br&gt;
Deno KV.&lt;/p&gt;
&lt;h2&gt;
  
  
  Architecture Overview
&lt;/h2&gt;

&lt;p&gt;Dengo is designed with simplicity and compatibility in mind. Here's how it&lt;br&gt;
works:&lt;/p&gt;
&lt;h3&gt;
  
  
  Core Components
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Database Class&lt;/strong&gt;: The entry point that manages collections&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collection Class&lt;/strong&gt;: Implements MongoDB-compatible operations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Query Engine&lt;/strong&gt;: Translates MongoDB queries to KV operations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Index Management&lt;/strong&gt;: Provides efficient querying capabilities&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Data Storage Model
&lt;/h3&gt;

&lt;p&gt;Dengo stores documents in Deno KV using a simple but effective approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Documents are stored with collection name and document ID as the key&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;collectionName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;documentId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;documentData&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For indexes, we use a similar pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Indexes use a prefix to distinguish them from documents&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;collectionName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;index&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;indexName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;indexedValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;documentId&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This storage model allows for efficient lookups by ID and indexed fields while&lt;br&gt;
maintaining compatibility with MongoDB's document model.&lt;/p&gt;
&lt;h2&gt;
  
  
  MongoDB Compatibility
&lt;/h2&gt;

&lt;p&gt;Dengo implements the core MongoDB API that most developers use daily:&lt;/p&gt;
&lt;h3&gt;
  
  
  Supported Query Operations
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;find()&lt;/strong&gt; and &lt;strong&gt;findOne()&lt;/strong&gt; with filtering&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;sort()&lt;/strong&gt;, &lt;strong&gt;limit()&lt;/strong&gt;, and &lt;strong&gt;skip()&lt;/strong&gt; for result manipulation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;projection&lt;/strong&gt; for selecting specific fields&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Supported Update Operations
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;updateOne()&lt;/strong&gt; and &lt;strong&gt;updateMany()&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;$set&lt;/strong&gt;, &lt;strong&gt;$unset&lt;/strong&gt;, &lt;strong&gt;$inc&lt;/strong&gt;, &lt;strong&gt;$push&lt;/strong&gt;, and other update operators&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;upsert&lt;/strong&gt; capability for insert-or-update semantics&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Supported Query Operators
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Comparison&lt;/strong&gt;: $eq, $gt, $gte, $lt, $lte, $ne, $in, $nin&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logical&lt;/strong&gt;: $and, $or, $nor, $not&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Array&lt;/strong&gt;: $all, $elemMatch, $size&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Element&lt;/strong&gt;: $exists, $type&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's a quick example of how Dengo's API mirrors MongoDB:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// MongoDB&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$gte&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Dengo&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$gte&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Implementation Details
&lt;/h2&gt;

&lt;p&gt;Let's dive deeper into how Dengo implements some key MongoDB features:&lt;/p&gt;

&lt;h3&gt;
  
  
  Query Processing
&lt;/h3&gt;

&lt;p&gt;When you execute a query like &lt;code&gt;find({ name: "John", age: { $gt: 30 } })&lt;/code&gt;, Dengo:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Checks if there's an index that can be used for this query&lt;/li&gt;
&lt;li&gt;If an index exists, performs an efficient range scan&lt;/li&gt;
&lt;li&gt;If no index exists, falls back to a collection scan&lt;/li&gt;
&lt;li&gt;Filters documents based on the query conditions&lt;/li&gt;
&lt;li&gt;Applies sort, limit, and skip operations&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Index Management
&lt;/h3&gt;

&lt;p&gt;Indexes are crucial for performance. Dengo supports:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single-field indexes&lt;/strong&gt;: Optimize queries on a specific field&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compound indexes&lt;/strong&gt;: Optimize queries on multiple fields&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unique indexes&lt;/strong&gt;: Enforce uniqueness constraints&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Creating an index is as simple as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createIndex&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Update Operations
&lt;/h3&gt;

&lt;p&gt;Updates in Dengo follow MongoDB's semantics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find documents matching the filter&lt;/li&gt;
&lt;li&gt;Apply update operators to modify the documents&lt;/li&gt;
&lt;li&gt;Write the updated documents back to the store&lt;/li&gt;
&lt;li&gt;Return metadata about the operation (matchedCount, modifiedCount, etc.)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Performance Considerations
&lt;/h2&gt;

&lt;p&gt;While Dengo provides MongoDB compatibility, it's important to understand the&lt;br&gt;
performance implications:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Indexed Queries&lt;/strong&gt;: Extremely fast, similar to native KV lookups&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-Indexed Queries&lt;/strong&gt;: Require full collection scans, which can be slow for
large collections&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complex Queries&lt;/strong&gt;: May not perform as well as in MongoDB, especially for
queries that would use specialized indexes in MongoDB&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For best performance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create indexes for frequently queried fields&lt;/li&gt;
&lt;li&gt;Limit the size of your collections&lt;/li&gt;
&lt;li&gt;Use more specific queries to leverage indexes effectively&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Type Safety
&lt;/h2&gt;

&lt;p&gt;One of Dengo's key advantages is its first-class TypeScript support:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ObjectId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// TypeScript will ensure you're using the correct fields and types&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;john@example.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$gte&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// result will be typed as User | null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Limitations and Future Work
&lt;/h2&gt;

&lt;p&gt;While Dengo aims to provide a MongoDB-compatible experience, there are some&lt;br&gt;
limitations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;No Aggregation Framework&lt;/strong&gt;: Complex data transformations need to be done in
application code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limited Transaction Support&lt;/strong&gt;: Only atomic operations on single documents
are fully supported&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Change Streams&lt;/strong&gt;: Real-time updates are not currently supported&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Future versions of Dengo will address these limitations as Deno KV evolves.&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Using Dengo is straightforward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Database&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dengo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Open a Deno KV database&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;kv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Deno&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;openKv&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Create a Dengo database instance&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;kv&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Get a collection&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;todos&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Insert a document&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insertOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Learn Dengo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Query documents&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;incompleteTodos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Dengo brings the best of both worlds to Deno developers - MongoDB's familiar and&lt;br&gt;
powerful API with Deno's native KV store. It's perfect for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Edge functions and serverless applications&lt;/li&gt;
&lt;li&gt;Projects migrating from MongoDB to Deno&lt;/li&gt;
&lt;li&gt;Developers who want a document database without external dependencies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We're excited to see what you build with Dengo! Check out our&lt;br&gt;
&lt;a href="https://github.com/copilotzhq/dengo" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; for more examples and&lt;br&gt;
documentation.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This post is part of the Dengo launch series. Stay tuned for more posts about&lt;br&gt;
performance optimization, migration strategies, and real-world use cases.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
