“Nestjs Mongoose -Schema verschachtelt” Code-Antworten

Nestjs Mongoose -Schema

// 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 Mongoose -Schema verschachtelt

// 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

verschachtelte JSON -Schema -Mongoose

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 -Wählen verschachtelt

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

Ähnliche Antworten wie “Nestjs Mongoose -Schema verschachtelt”

Fragen ähnlich wie “Nestjs Mongoose -Schema verschachtelt”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen