How do I add an index for the updatedAt system field? - azure-mobile-services

I know you can add an Index attribute to a field of an EntityData subclass, which creates an SQL Server index. I would like to know how to do the same for system fields like updatedAt.

I would like to know how to do the same for system fields like updatedAt.
I suggest you could set index for updatedAt field in portal directly. And from this article, you could see the updatedAt field is readonly. So you can not change it.

Related

What should I use as validation tool using NestJS and MongoDB?

Let's say, I am creating application using NestJS. I use MongoDB as a database and mongoose as ODM. So, NestJS has it's own way to validate data - ValidationPipe's. On the other side, there is mongoose built-in ways to validate data that being pushed into DB.
The question is - can I use only NestJS validation or do I need also second-check my data using mongoose validation tools?
Personally, I can't see why should I use additional layer of validation if I already have NestJS validation. But maybe there is best-practice or something?
Each database validates input data and emits an error if found. However, you must take into account your schema file. For instance, if you are using Prisma(It doesn't actually matter) and you have a User model like below
model User {
id String #id #default(auto()) #map("_id") #db.ObjectId
email String #unique
password String
name String
image String?
createdAt DateTime #default(now())
updatedAt DateTime #updatedAt
##map("user")
}
As you can see there is only one optional property "image". Whether you pass a value for image property or not, the database will insert the data as a row. On the other hand, the properties without "?" mark at the end of the type, will not be stored if you don't pass them and emit an error.
Therefore, if you modeled schema according to your business logic, you don't need to validate twice but only add an exception handling like the one below.
const user = await this.usersService.findOne('id...')
.catch((e) => new NotFoundException({ message: 'No user found.' }))

How to get timestamp for any attributes in Orion

I've my context in Orion within multiple attributes;
how can I also get the attributes' timestamp ("modDate") via GET query?
Thank you so much
According with Builtin Attributes documentation (to which dateModified belongs):
Builtin attributes are not rendered by default. In order to render a specific attribute, add its name to the attrs parameter in URLs (or payload field in POST /v2/op/query operation) or subscription (attrs sub-field within notification).
So, in the case of GET, you have to use something like this:
GET /v2/entities?attrs=*,dateModified
The * is needed to include all the regular attributes. If you ommit it and use just ?attrs=dateModified you will get only dateModified and no other attribute.
EDIT: in the case you want to get not the entity dateModified attribute but the attribute dateModified metadata is similar. In this case, from Builtin Metadata documentation
Builtin metadata are not rendered by default. In order to render a specific metadata, add its name to the metadata URL parameter (or payload field in POST /v2/op/query operation) or subscription (metadata sub-field within notification).
So:
GET /v2/entities?metadata=*,dateModified

Is there a way to set up MongoDB ttl indexes using prisma

I am trying to make a Hotel website backend that allows users to reserve rooms using GraphQL and prisma. I want to make sure that the reservation will be cancelled after the check-in time if no one has checked in. To do this I wanted to set up a ttl index that will delete the reservation.
If there is any alternative way of doing this you can help me.
take a look on this : https://www.prisma.io/docs/concepts/components/prisma-schema/indexes
model Post {
id Int #id
title String #db.VarChar(255)
content String #db.Text
##fulltext([title, content])
}

User Defined Fields storage in Postgresql

I'm looking at building a system which will include user created fields which will use Postgresql as the database. I've read that the EAV model for this isn't great and that a jsonb column to store the custom fields will be the best route.
I want the user to be able to build their own queries to the data as well so is the best way to go to store the custom field names in a table and store the actual data in the jsonb column, that way when it comes to building the queries the webapp can query the custom fields table for a reference as to what fields are available and their types?
Tickets
ID
WhenCreated
LastUpdated
CustomProperties {JSON B column, key value pairs where the key names will be stored in the custom fields table}
Customfields
ID
FieldName
WhenCreated
FieldTypeID
FieldTypes
ID
FieldTypeName {String, Date, etc}

_id field with persistent-mongodb

I'm building a web application in yesod with mongodb.
I'm tryign to create a model called Message:
Message
_id Text
threadKey Text
body Text
But I can't seem to access the _id field this way, the message_id function doesn't get created, unlike messageThreadKey and messageBody.
How can I access the _id field of mongo objects from yesod/persistent-mongoDB?
In persistent the id (in both the SQL version and the Mongo version) is special and not actually part of the model record. The combination of a Id and a Model Record is called an Entity.
I would reread the persistent chapter of the Yesod book under the Manipulation section, Insert subsection.
http://www.yesodweb.com/book/persistent