Questions tagged [mongoose-schema]

Everything in the Mongoose ODM starts with a Schema. Each schema maps to a MongoDB collection and defines the shape of the documents within that collection.

Everything in the Mongoose ODM starts with a Schema. Each schema maps to a MongoDB collection and defines the shape of the documents within that collection.

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

var blogSchema = new Schema({
  title:  String,
  author: String,
  body:   String,
  comments: [{ body: String, date: Date }],
  date: { type: Date, default: Date.now },
  hidden: Boolean,
 meta: {
  votes: Number,
  favs:  Number
 }
});

Related Links

3348 questions
0
votes
0 answers

Why its not rendering welcome page when I click Sign in button?

app.js const express = require('express'); const bodyParser = require('body-parser'); const ejs = require('ejs'); const mongoose = require('mongoose'); const app = express(); app.use(express.static('public')); app.use(bodyParser.urlencoded({…
0
votes
0 answers

What is the change in mongoose version 5 & 6 for model function

import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; import { Document, Schema as MongooseSchema, model } from "mongoose"; export type BookDocument = Book & Document; @Schema() export class Book { _id: MongooseSchema.Types.ObjectId; …
user11931176
0
votes
1 answer

Getting "path is required" error in Mongoose schema

I try to test post request in thunder vscode to create new order but it gives me this error in screenshot. I send post request in format json but the error is not resolved; when I remove required from ordermodel it works. This is my node version:…
0
votes
0 answers

How to use BinanceAPI candlesticks with MondoDB timeseries?

I'm trying to implement simple multi charts ui. I watched MongoDB presentation for financial timeseries with candlesticks. As I understand timeseries works as flat structure, and I should put there ticks. timeseries: { timeField: "time", metaField:…
Odinn
  • 1,106
  • 9
  • 28
0
votes
1 answer

How to use Mongoose Aggregate to statistics sum and sort

This is my schema: let ORDER = new Schema({ playername:String, serverUID:String, amount: Number, ADMIN_UID: String, status: Boolean, objid:Array, }) I need to sort by ServerUID, then sort by objid and status is true, then…
Jeremy Wu
  • 11
  • 1
0
votes
1 answer

Mongoose creates empty document with next.js

I'm struggling with what should be a simple case, but I can't seem to get to the bottom of it: I am building a very simple CRUD app with nextjs using MongoDB. I am following the official nextjs "with-mongodb-mongoose" as a guide…
axeldc
  • 1
  • 1
0
votes
0 answers

Schema.name undefined while making Many-To-One relation reference with Nestjs & MongoDb

I want to attach and see all the posts of the user inside posts property of UserSchema. The user/Author id is getting stored with posts. But when I try the get posts ids I'm getting the following error. @Prop([{ type:…
M Nouman
  • 437
  • 1
  • 5
  • 22
0
votes
0 answers

How to generate auto increment count field using Mongodb Schema

I have a database related to the interview process which consists of multiple fields. basically, there are 5 APIs POST - (Candidate info) - for entering candidate data PATCH - for updating candidate info PATCH - (for Short Listing and reviewing) -…
0
votes
0 answers

I'm getting a 400 error when I try to create a new Item on my model that is referenced to another model, am i missing data to send to the backend?

I'm creating a full stack MERN stack app, my front end is getting passed down the categories prop which is the model that i'm referencing to create a new Item, which is the model i'm trying to create on. I'm getting a 400 error when I use the form…
Shea Shea
  • 11
  • 1
0
votes
0 answers

Mongoose find parent if children count is greater than 5 by grouping children of another table

I want to find only 20 Parent records in LIFO order if it has more than 5 children. Children is a different table. Highly appreciate your help! Parent table name - Content import { model, Schema, Model, Document } from "mongoose"; const…
Bibek Das
  • 35
  • 10
0
votes
1 answer

Set a limit for an array in mongoose schema

I'm trying to create a mongoose Schema and set one of its fields' type to be an Array But I need to limit that array by default, which means if we tried to add a new Item to that array when it's filled with the limit count, it refuses to take this…
0
votes
0 answers

How to validate schema at object level in mongoose?

I want to validate an object in mongoose schema, i.e here is my schema - logs = new Schema({ user_id: String, reminder_cat: String, activityNote: String, sent_email: Number, added_date: Date }) I want to validate if reminder_cat…
Jeet
  • 5,569
  • 8
  • 43
  • 75
0
votes
0 answers

Mongoose update document created with base model to model derived from base model with discriminator function

I have a base model name as userModel and i have inherited that base model and created another model name as adminModel with some extra fields with discriminator. User Model const { Schema } = require("mongoose"); const mongoose =…
0
votes
0 answers

How to store a checkbox value as array in mongoDB with mongoose

I would like to store checkbox a value as array in mongoDB, using mongoose schema. I can get the values in array if I check more than 2 boxes. But as string when I check only one. The following is for the checkbox in form in ejs file
Miki
  • 1
0
votes
1 answer

MY MONGOOSE MODEL IS NOT SAVING IN MY MONGOSH DATABASE

Hello I am NEW to this and I am trying to save the Amadeus object I created into mongosh using the method .save() When I connect to my file through node I can see the Amadeus object and edit but when I do amadeus.save() and then go and check my db…