denoDB

denoDB

  • Docs
  • GitHub
  • Help

›Clients

Guides

  • Getting started
  • Connect to a database
  • Clients

    • Using MariaDB
    • Using MongoDB
    • Using MySQL
    • Using PostgreSQL
    • Using SQLite
  • Create models
  • Synchronize database
  • Query models
  • Transactions
  • Relationships

    • Foreign key
    • One-to-one
    • One-to-many
    • Many-to-many
  • Model events

API Reference

    Models

    • Data types
    • Field descriptors
    • Model methods
    • Model records

Using MongoDB

DenoDB is using deno_mongo for MongoDB support.

import { Database, MongoDBConnector } from 'https://deno.land/x/denodb/mod.ts';

const connector = new MongoDBConnector({
  uri: 'mongodb://127.0.0.1:27017',
  database: 'test',
});

const db = new Database(connector);

If you need to connect to your instance using more options than a bare URI, check the available options from deno_mongo client. Remember to keep the database field in your options as this remains required.

Models

Using Mongo means adapting your models to its standards, one being the use of _id for identifying records. The only change on your side is to add an _id field to your models:

class Flight extends Model {
  static fields = {
    _id: {
      primaryKey: true,
    },
  };
}

More on models in the according section.

Last updated on 1/2/2021 by eveningkid
← Using MariaDBUsing MySQL →
  • Models
Docs
Getting StartedAPI Reference
More
GitHubStar