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

Delete item (react, node, mongoose)

I just need some advice here, i cant seem to delete an item thats in my nested array in my User model (user.likedSongs[]). React button to delete function: const handleDelete = async (e, index) => { const trackToDelete =…
Hanksy
  • 5
  • 3
0
votes
1 answer

toArray is not a function in mongodb,mongoose

to Array is not a function in mongo database, mongoose, node.js `getCartProducts: (userId) => { return new Promise(async (resolve, reject) => { let cart Items = await db.cart.aggregate([ {`your text` …
0
votes
1 answer

Beginner of Node.js and MongoDB. I just wondering why there is no "isAdmin" in my MongoDB?

Beginner of Node.js and MongoDB. I just wondering why there is no "isAdmin" in my MongoDB and how to fix it? Thank you~ import mongoose from "mongoose"; const UserSchema = new mongoose.Schema( { username: { type: String, required:…
0
votes
0 answers

expected undefined to equal 'String'

I am new to JS and I am trying to create a model with Mongoose but I get the following error: expected undefined to equal 'String' from the test system. This is my code to create the model: ` // CREATE MODEL: Album const mongoose =…
0
votes
1 answer

How to store general data of a application in mongodb (mongoose)

i am working on a app inwhich anyone can purchase a product when one place his order there is some extra charges added i.e minimum delivery charge, GST, and these values are gereral data of my app, i just want to read and calculate accordingly, i…
0
votes
0 answers

How to properly Store and structure my data in Mongo db

I am having one problem while working on Mongo db with an Node js project, I am creating a Meeting Scheduler project where a user(admin) can create an account and register his company on our project and that company has 1000 members and few teams…
0
votes
1 answer

MongoDb-Need Count of all documents before grouping in aggregate query

I want count of all documents before doing grouping as show in my Query. The purpose of this if ai get count of all documents then I can calculate Percentage(%) of each individual students count. I tried with $count but after using that I'm not able…
Om Adde
  • 21
  • 2
0
votes
0 answers

mongoose query middleware getFilter not working

I want to apply throwing errors for all "one" operations where the document is missing. I'm following the advice from one of mongoose collaborators: mongoose.plugin((schema) => { schema.post(/One/, function (doc, next) { if (doc) return…
Shining Love Star
  • 5,734
  • 5
  • 39
  • 49
0
votes
0 answers

Removing a nested document in mongo db using mongoose

I am facing problems while removing a nested document in mongo db using mongoose. The schema looks like this const iLevelPlanning = new mongoose.Schema({ istep: String, maturity, milestone: [milestone], buildingPhase:…
Gana
  • 1
  • 1
0
votes
1 answer

Is there a way to use single Mongoose schema for multiple collections

I've created an API for some entities, each of which have their own schema and a corresponding collection. Such as: posts authors comments There is one to one relationship between posts and authors, and one to many relationship between posts and…
Gaurav
  • 347
  • 4
  • 12
0
votes
1 answer

how to exclude an field value that inside an array object during mongoose find query

...... ...... @Prop({ type: [ { line_item_uid: { type: String }, product_ref_id: { type: mongoose.Schema.Types.ObjectId, ref: "Product", select:false }, image: String, …
0
votes
1 answer

How to fetch all data only from mongoose with Nodejs

I am not able to fetch all the data from mongoose. When I tried to fetch data it create new collection name(signins) with empty, but singin collection already exists. I don't understand what I am doing wrong here Index.js File const express =…
Amit Sharma
  • 31
  • 1
  • 12
0
votes
1 answer

I'm working on my project and facing a problem in deleting a element in an array of objects

I'm working on my project and facing a problem in deleting a element in an array of objects ,the mongoose function run without error but the targated element won't delete at all .Help me with the code. i want to delete the element of document(user)…
0
votes
1 answer

Extend Document class or & Document with Mongoose Schemas?

I am using NestJS to write some backend code and fetch objects from MongoDB. The examples they offer in their documentation create a class annotated with @Schema() and then concatenate it with their built-in mongoose Document class. @Schema() export…
Mike M
  • 4,879
  • 5
  • 38
  • 58
0
votes
2 answers

Mongoose min number validation doesn't work while inserting data

Using Node, Express and Mongoose, I'm trying to insert data into MongoDB through a POST method. The fields I'm trying to insert has a phone field on which I'm trying to assign a validation that will check if it has minimum ten digits. Otherwise,…
priyamtheone
  • 517
  • 7
  • 22
1 2 3
99
100