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

reading and uploading to mongodb through schemas

I'm very new to node and mongoose schemas, so this might be a noob question. I'm trying to fetch the data to display on my home page. Right now, the home page uses a function in a separate file to call the Api and fetch from the backend, which seems…
0
votes
0 answers

Failed to load function definition from source: Failed to generate manifest from function source

I am trying to deploy the following code in firebase function but getting the following error : Error: Failed to load function definition from source: Failed to generate manifest from function source: Error: Counter already defined for field…
akm
  • 149
  • 1
  • 9
0
votes
2 answers

NodeJS/Mongoose Empty String Not Considered Valid

In a schema for a collection I have in Mongoose, I have a string value required like so for a particular model: preExecutionText: { type: String, required: true } However, if I try to store an empty string for this property, I get this…
0
votes
1 answer

How findOneAndUpdate Method works, getting null as a result

What i am trying to create, find a comment based on commentId also finding that particular comment which should not be postedBy currently loggedin user I am trying to create commentVote functionality, loggedIn user cant vote his comment or…
0
votes
1 answer

I have issues in reverse relation in nodejs using moongose one to one relationship

So bassically I have three roles for users admin seller buyer This is my User Scheme const userSchema = mongoose.Schema({ email: { type: String, required: true, unique: true }, password: { type: String, required: true, select: false }, role:…
0
votes
2 answers

How to display a field from reference model

I want to get the name of the user, using the Reserves model, because that's the one I can display. The **User ** model is referenced in the **Reserve ** model. and the only thing I can get is the Object ID. How can I get other field values from the…
0
votes
1 answer

How to return available filters along with search query in elastic search

Basically im pretty new to elastic search and need some help in querying. Also let me know if i need to make any changes to my MongoDB Schema I want to know how do i search in elastic search which would give me available products based on query and…
0
votes
1 answer

How to Remove more than one documents from mongodb

I am trying to deleteFeature meanwhile i want all the comments related to that feature deleted but i don't know how to do it. my deleteFeature method - exports.deleteFeature = (req, res) => { try { const { slug } = req.params; …
0
votes
1 answer

How to find and populate reference object fields in a mongoose schema

I'm trying to fetch data from below mongoose schema, But I'm not sure how to fetch the role field, which is a type of RoleObject. import * as mongoose from 'mongoose'; const Schema = mongoose.Schema; const RoleObject = { current_role: { …
0
votes
1 answer

Float Datatype is not defined in mongoose-express database schema

I am using express with mongoose in mongodB's local type (mongodB compass). I was defining float type of datatype while creating a schema in mongoose, but it is showing me an error [here is the error] (https://i.stack.imgur.com/WFAGM.png) what if we…
0
votes
0 answers

why _id is set to null for subdocuments in default in mongoose

i need a _id for my subdocuments but it set default to null,but the field _id id generated automatically but the value set to null, i tried in many ways but is default value null is not changed. method 1 const event_Schema = mongoose.Schema({ …
Venkat Cpr
  • 153
  • 1
  • 11
0
votes
4 answers

How can I join two collections from different databases in mongoDB?

I have two collections Post (belongs to posts database) and User (belongs to account database). My requirements to do join on these two collection. But I am unable to reproduce my requirements. I am expecting joins on two collections.
0
votes
0 answers

MissingSchemaError: Schema hasn't been registered for model "Category". Use mongoose.model(name, schema) Using NextJs and Mongoose

When I try to populate a category from the products it shows **MissingSchemaError: Schema hasn't been registered for model "Category". Use mongoose.model(name, schema) Using NextJs and Mongoose ** My Product Schema Schema Prorduct My Category…
0
votes
1 answer

trim validation is not working for array in mongoose

I have tried to add a default trim validation to array but I don't understand why it is not working out. should Iterate elements in array to add trim or will it apply to each element in collection? I trim the below code assuming that trim will work…
0
votes
1 answer

mongooseError: Operation `users.insertOne()` buffering timed out after 10000 ms

When i run mongoose in this code it seems to me as if it doesnt connect to my database in time. It is a local mongodb database and not atlas. The error: mongooseError: Operation users.insertOne() buffering timed out after 10000 ms occurs when i do…
asdaw1
  • 13
  • 4