$ npm install --save @nestjs/mongoose mongoose
var mongoose =require('mongoose');
var Schema = mongoose.Schema;
var msg = new Schema({
messageType: String,
timestamp: Number,
messagestatus: String
});
var standardmessage = new Schema({
id: Number,
name: String,
type: String,
message: [msg]
});
// 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);
// 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);
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
}
});
var fields = { 'properties.OBJECTID': 1, 'properties.TIMESTAMP': 1 };
var query = Feature.find({id: 1}).select(fields);
var jobSchema = Schema({
negotiation: { state: { type: String, required: hasNegotiation } }
});
function hasNegotiation() {
return this.negotiation && Object.keys(this.negotiation).length > 0;
}