“NESTJS SCHEMA MONGOOSE NEST” Réponses codées

schéma de manongoose Nestjs

// user.schema.ts
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type UserDocument = User & Document;

@Schema()
export class User {
  @Prop({ type: String, unique: true })
  username: string;
  
  @Prop({ type: String })
  password: string;
}

export const UserSchema = SchemaFactory.createForClass(User);
Embarrassed Earthworm

NESTJS SCHEMA MONGOOSE NEST

// user.schema.ts
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type UserDocument = User & Document;

@Schema()
class NestedData {
  @Prop({ type: String })
  foo: string;
  
  @Prop({ type: Number })
  bar: number;
}

@Schema()
export class User {
  @Prop({ type: String, unique: true })
  username: string;
  
  @Prop({ type: String })
  password: string;

  @Prop({ type: NestedData })
  data: NestedData;
}

export const UserSchema = SchemaFactory.createForClass(User);
Embarrassed Earthworm

Mongoose de schéma JSON imbriqué

var mongoose =require('mongoose');
var Schema = mongoose.Schema;

var standardmessage = new Schema({
  id: Number,
  name: String,
  type: String,
  message: {
    messageType: String,
    timestamp: Number,
    messagestatus: String
  }
});
Alive Alligator

Mongoose sélectionné imbriqué

var fields = { 'properties.OBJECTID': 1, 'properties.TIMESTAMP': 1 };
var query = Feature.find({id: 1}).select(fields);
florinrelea

Réponses similaires à “NESTJS SCHEMA MONGOOSE NEST”

Questions similaires à “NESTJS SCHEMA MONGOOSE NEST”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code