0

I got stuck on integrating Nest JS with Cosmos DB Core SQL API. I am aware that there is a module for Cosmos DB (https://github.com/nestjs/azure-database) but I need the data schema to support nested json like this:

{
    "id":"string",
    "name":"string",
    "start_date":2016-06-01T00:00:00.000Z,
    "end_date":2016-06-01T00:00:00.000Z,
    "current_status":{
        "event_part_id":"string",
        "media_type":"string",
        "media_id":"string",
        "media_time":int
    },
    "event_parts":[{
        "id":"string",
        "name":"string",
        "timeline_id":"string",
        "user_voice_chat":boolean,
    "surveys":[{
        "id":"string",
        "name":"string",
        "question":"string",
        "answers":[{
            "id":"string",
            "name":"string"
        }],
    }],
    "images":[{
        "id":"string",
        "name":"string",
        "url":"string"
        }],
    "videos":[{
        "id":"string",
        "name":"string",
            "url":"string"
        }],
        "live_streaming":{            
            "id":"string",
            "name":"string",
            "url":"string"
        }
    }],
    "asset_id":"string",
    "twitter_text":"string",
    "rtc_network_room_id":"string",
    "is_active":boolean
}

Which I think (or I'm probably wrong) the @nestjs/azure-database does not support, since when I checked their example and quickstart there is no example for such json schema.

Is it possible to use @nestjs/azure-database or do I need to create a custom database module for this?

I am also aware that there is an option to use Cosmos DB MongoDB API and use TypoORM or Sequelize for this, but internally we want to keep using Cosmos DB SQL API since we are already using it for several services.

Thanks!

1 Answer 1

0

The docs on the Github Page show that you can work with complex object types when targeting CosmosDB.

import { CosmosPartitionKey, CosmosDateTime, Point } from '@nestjs/azure-database';

@CosmosPartitionKey('type')
export class Event {
  id?: string;
  type: string;
  @CosmosDateTime() createdAt: Date;
  location: Point;
}

Will be automatically converted to:

{
  "type": "Meetup",
  "createdAt": "2019-11-15T17:05:25.427Z",
  "position": {
    "type": "Point",
    "coordinates": [2.3522, 48.8566]
  }
}

Note the nested object for postition and conversion of the Point type.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Jesse, thanks for the answer! To add more context to the question: * Yes, I understand that we can work with complex object types on Cosmos DB SQL API. * About the Point type, yes I am also aware that it exist. It's just that it is not the type that I'd need. I'd like to have a custom complex object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.