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

How do I return data from an aggregation of MongoDB with NodeJS?

I am trying to create a cards game but I am stuck at the point of returning cards with MongoDB: player has 30 cards, when clicking on a card the card does an animation with translate and rotate to reveal the value of the card , and since I only need…
kangaroo
  • 11
  • 4
0
votes
0 answers

Mongoose Error TypeError: Cannot read properties of undefined (reading 'length')

Anyone can help here? This is the situation App.js and this is the error: Error i am trying to connect my app to mongoose but i continuing to have issues
UXdev88
  • 1
  • 2
0
votes
1 answer

how do i simplify aggregation pipeline result

i am trying to return aggregation result based on user's role and active status sample doc { "email": "doe@gmail.com", "firstName": "doe", "lastName": "bghh", "phone": "+919016703350", "password":"$.5GIV3q9JqzRqY/lP2", "status": "verified", …
0
votes
0 answers

Href opening link in http://localhost:3000/LINK rather than opening the link seprately

I'm making a first basic MERN Stack where users can enter their name, age and give one link for their social media as like a log book that they visited the page. After taking the link from the user in schema as follows const UserSchema = new…
0
votes
0 answers

how do i change language of mongoose errors(validation errors etc)

I am working on a node project in which i need to display mongoose errors in a different language. I tried overriding default mongoose errors, i.e mongoose.Error.messages with my custom messages, it works. But i need a configurable solution in which…
0
votes
0 answers

Change Message Schema for polls || mongoose

This is the message schema I have been using so far... { sender: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: [true, "Please Provide Sender"], }, content: { type: String, max: [2000,…
0
votes
1 answer

How to access nested elements of json object in node js and mongodb

const mongoose = require("mongoose"); const productSchema = mongoose.Schema({ product_name: { type: String, required: [true, "Must Enter Product Name"], }, product_brand: { type: String, }, category: { type: String, …
0
votes
1 answer

Allowing a Empty Object ID Mongoose,

I have two models User and Company. in the User I am storying the Company._ID, to associate users with a company. I have both of the models CRUD capability working as I can create a user associate it with a company and I can Create a company with…
CG33
  • 15
  • 3
0
votes
1 answer

How to return matching nested elements in mongoose?

Let's say this is the complete document { "_id": "63aadd124fabe6c7f5cb3af5", "url": "https://github.com", "sender": "username@gmail.com", "recipients": [ { "email": "recipient1@gmail.com", "code":…
0
votes
0 answers

Mongoose sort enum by position instead of alphabetical order

I have a mongoose schema where I use an enum: const sessionSchema = new mongoose.Schema( { date: { type: Date, required: true, }, sessionType: { type: String, enum: eSessionType, required: true, }, …
0
votes
2 answers

$set { "array.index.value" :"newvalue"} use something instead of index or use variable

I am using mongoose to store user data, and one of the attributes is items: [] in my additems.js: const User = require('../models/User'); var array = user.items array.indexOfObject = function (property, value) { for (let i = 0,…
0
votes
0 answers

Database of my project (donars) is not getting stored on Mongodb,it always shows no connection on the terminal. Help me in finding the error

`//here is my code const mongoose = require("mongoose"); mongoose.set("strictQuery", false); mongoose.connect("mongodb://localhost:27017/donars",{ }).then(() => { console.log(connnection successful); }).catch((e) => { console.log(no…
0
votes
0 answers

Finding child Documents from parent modal - mongodb

I have User Schema and View Schema such that each user have multiple view documents Here is my views schema var ViewsSchema = mongoose.Schema( { userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', }, …
Muhammad Sami
  • 520
  • 2
  • 8
  • 21
0
votes
1 answer

Node.js- Add new field in array of Mongodb object

I have a collection of users that has an array of multiple plates : users : [ { _id: '61234XXX' plates: [ { _id: '123' 'color': 'orange' }, { _id: '124' 'color': 'blue' } ] }, { _id: '63456XXX' plates: [ { _id: '321' 'color':…
Gurneet Singh
  • 39
  • 1
  • 6
0
votes
1 answer

Mongoose - express server update specific index in array of objects

I've created a custom identifier ID and I'm trying to update my coins and aswell as the first array object purchased bool to true. this is how my data looks like [ { "identifier": "123456789", "coins": 100, …