Questions tagged [mongoose]
Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.
46,067
questions
0
votes
1
answer
10
views
How to update "order" field in mongodb multiple documents collection accroding to request array?
I use this code to do this:
const update = async (item) => {
await Service.updateOne({ _id: item._id }, { order: item.order });
};
arr.forEach((item) => ...
0
votes
0
answers
5
views
MongoDB nesting ancestor elements into parent
I have a number of comments made on a post.
[id: 10] Root comment
|
|-- [id: 11] Reply to root
| |
| |-- [id: 12] Reply to reply to root
| |
| |-- [id: 13] Bottom comment in this chain
...
-1
votes
1
answer
12
views
exactly why this error are show i can't understand. this is the mongoose conncetion with node js
connection.once('open', () => {console.log('DB Connected!')}).catch((err) => {
^
TypeError: connection.once(...).catch is not a function
This error are shows when server startedenter image ...
0
votes
0
answers
11
views
How to fix Discord bot v14 TypeError: Lotteries.save
My current problem is that i cannot show only the pot here is the current error :
Also if i read the Lotteries.pot value it says "undefined"
pot.js:50 await Lotteries.save()
^
TypeError: ...
1
vote
1
answer
24
views
MongoDB - Mongoose: How to query this? "populate()" dosen't work. it's show "null"
I have a page schema, the page schema has two object properties createdBy and approvedBy.
when I used
.populate("approvedBy").populate("createdBy"); then show "approvedBy"...
0
votes
1
answer
15
views
Some data returns undefined using RTK Query
This is my first time using Redux, what happens is that I am trying to show data in a Material UI Select, and when I show the user name it works perfectly, I did the same for the partner's data, but ...
1
vote
1
answer
21
views
MongoDB find in sub-document of a sub-document
I have a document structure with a reference to another document that itself references an additional document: A->B B->C.
I'm trying to perform a find operation on A by the _id of the document ...
0
votes
0
answers
6
views
how solve this issue "SyntaxError: Identifier 'jest' has already been declared" [closed]
Tengo una aplicacion con express y mongoose y le estoy haciendo test con jest, entonces cuando corro mi test, que no tiene que hacer consulta a bd, me tira este error, ya previamente habia configurado ...
0
votes
1
answer
9
views
Passport seem to not set properly req.user after initialization
I use Mongoose (connected to a mongoDB atlas cluster), ExpressJS, and NodeJS to make a login/authentication system but after login and initialize with Passport, req.user doesn't return the user info ...
-3
votes
0
answers
11
views
Error: Cannot find module './database/db.js '
I want to do the find operation using MongoDB. but I got such an error. I've tried version changes, but I can't get any results.
I've tried version changes,changing the collection.
0
votes
0
answers
9
views
Why Am I Getting Type error, mongoose.model is not a function?
I am working on a project which was working fine but when i went to try it again, I got this error:
error - TypeError: mongoose.model is not a function
This Is My Code:
Schema:
const mongoose = ...
0
votes
0
answers
11
views
log the mongoose queries for a request-response cycle in express
I am trying to log the queries getting executed on the mongoose connection in one express request.
export default (req, res, next) => {
mongoose.set("debug", (collectionName, methodName,...
0
votes
0
answers
12
views
In array of objects, populate a field Property in Mongoose aggregate Pipeline
I have a Product Model that has the following schema
const product = {
...other fields,
ratings: [
{
star: Number,
postedBy: {
type: ObjectId,
...
-1
votes
0
answers
14
views
how to use lookup same model but two aggregation operation
//const { default: mongoose } = require("mongoose"); const GetOrderBySingleSellerService = async (req, model) => { try { let ID = mongoose.Types.ObjectId(req.params.id); let ...
0
votes
1
answer
18
views
How to get specific array objects from different documents in MongoDb
I'm getting an issue. The problem is, I've multiple collections each collection has dimension field, that contains array of objects of different dimensions. The collection looks something like below.
...
0
votes
0
answers
14
views
Mongodb Update object if it match one key
I have collection named list.list collection has documents like this.
{
name: 'mimi',
items: [
{
ID: 'one',
count: 100
}
]}
I want to update the count inside object if ...
0
votes
0
answers
14
views
Yet another next.js/mongoose/ts authentication user schema error
I'm experiencing a typing related problem with an instance method I've added to my mongoose schema. I've imported the default export of the file below into my api folder file in order to use it there (...
0
votes
1
answer
12
views
Nest can't resolve dependencies for MongoDB
I am trying to use MongoDB in my Nest.js project. It seems like I have installed everything correctly, but I keep getting this error:
Nest can't resolve dependencies of the AuthService (...
0
votes
0
answers
10
views
Role Based Access Control with User Defined Roles
I'm learning Mern Stack Development by making a Ecommerce Web app. I'm stuck at a feature that i want to add. The thing i want to add is "Users when registers to my website they have a role of &...
1
vote
2
answers
28
views
Remove document where populated data is empty after match
I'm trying to add filter on populated data.
"populate": [
{
"path": "attachments",
"select": "_id type",...
0
votes
0
answers
18
views
Why is a document created even when the required fields are missing
I'm workingo on a Express, Node.js, and MongoDB project where a user can create a manga document to track it.The required fields are the name and artist fields, which both are Arrays of Strings, ...
0
votes
0
answers
22
views
how to sort and filter mongoDb model using mongoose
import mongoose from "mongoose";
const hotelSchema =new mongoose.Schema({
name:{
type:String,
required:[true, "Please enter hotel name"],
trim:true
},
description:{
type:...
-1
votes
0
answers
13
views
Mongoose is failing to retrieve data [closed]
Mongoose is failing to retrieve data from MongoDB after the Version Change
previously i have the version 5.9.3 after that i updated the version to 6.0.0 then
here the problem starts.
I have changed ...
0
votes
0
answers
10
views
next js and mongoose / error while passing props / Maximum call stack size exceeded
I am using the app directory next js.
In the server component, I make a request to mongodb:
const user = await User.findOne({name:'Alex'})
It works well. I can get information about the 'user' in the ...
1
vote
1
answer
44
views
mongodb $lookup operator based on key name
Having two collections tables and table_rows like following:
tables = {
"_id": "641ce65852a7ccd2f4a7b298",
"name": "table name",
"description": &...
-1
votes
0
answers
18
views
Model.FindOne() No longer accepts a callback, leveling system
I'm trying to create a leveling command and i get this log everytime i write somehting:
node:events:491
throw er; // Unhandled 'error' event
^
MongooseError: Model.findOne() no longer accepts a ...
0
votes
2
answers
24
views
Error MongoNotConnectedError: Client must be connected before running operations - how to get rid of the error?
I am creating a project where I am using a seeds file to seed my DB with test data.
When I run the file in node.js, here is the error I get:
Database connected
D:\OUWork\Year 6\TM470\Project\...
0
votes
0
answers
6
views
Figma plugin doesn't connect with my database?
import { connect } from 'mongoose';
const user = "santizapataalvares"
const passwor = "tiago1223"
const db = "AutUserX"
const uri = `mongodb+srv://${user}:${passwor}@...
1
vote
1
answer
24
views
Mongoose Update Nested Array Object
I have a MongoDB collection as follows
[
{
actions: [
{
_id : ObjectId('641b34b7aa7f4269de24f050')
participants: [
{
_id : ObjectId('...
1
vote
2
answers
14
views
MongoDB Aggregation with Mongoose in Route
Messing around with aggregations in MongoDB in a Node / Express app with Mongoose. Here's the route:
router.get("/search", async (req, res) => {
let movies;
if(req.query.search){
...
0
votes
0
answers
10
views
Delete all result from map objects then save it using expressjs
I'm trying to figure out if it's possible to delete all the mapped objects? This is actually from my test database. I'm trying to clear out all the orders for each object.
this is the example
{
...
0
votes
1
answer
17
views
How to perform where in clause with Mongoose aggregate function
I have these two mongoose documents
[
{
"_id": "63a7b67b333394043fdca934",
"name": "Macbook M2 PRO",
"category&...
1
vote
1
answer
11
views
How to define a default function on a mongoose schema?
After spending a few hours now on this issue i have resorted to SO.
I am running into promise pending errors on the following field I want to assign a default value for:
friendlyId: {
type:...
0
votes
1
answer
27
views
Mongodb query to find document matching a particular range
I have a problem in which I am getting distance between two geolocations. I have a MongoDB collection in which I have documents that have min_distance, max_distance, and price. I need a query to fetch ...
0
votes
1
answer
18
views
Nest, typegoose error on console `throw new Error(`Invalid ${type} object`);`
hello everyone i have a problem i want to implement many to many on typegoose when i use
export const PortfolioModel = getModelForClass(Portfolio);
getting this error throw new Error(Invalid ${type} ...
3
votes
2
answers
37
views
How to perform full text search in mongoose aggregrate
Given a mongoose object. How can I do a full text search in document object
{
"product" :[
{
"_id": "633d32c4ea9b06177e183388",
"...
1
vote
1
answer
13
views
Mongoosastic search function undefined when using typescript
I'm using mongoose v6.0.0, and mongoosastic v5.0.0 and typescript when I try the following code after initializing the plugin and trying to set the types correctly it still tells me that PageModel....
0
votes
0
answers
22
views
TypeError: branch is not a function on validating with yup
When trying to validate using the Yup library, the error "branch is not a function" is being thrown in the following function (I have commented out the schema.validate function in that case ...
0
votes
1
answer
18
views
How to find documents that contain certain value in any of sub-object's key-value mongoose/MongoDB
I'm trying to find if some document exists that match 2 filters :
licenseType = "Trial"
machineId object contains at least one value that match "ABC"
Normally, in javascript, I ...
Staging Ground
Major changes
Staging Ground question
The Staging Ground allows new users to be connected with community members willing to offer guidance on writing a good question in a private space.
mongodb atlas not connecting
throw new error_1.MongoAPIError('URI must include hostname, domain name, and tld');
^
MongoAPIError: URI must include hostname, domain name, and tld
at resolveSRVRecord (C:\Users\shamnadks\...
0
votes
0
answers
10
views
how to update sub document in mongoose+express.js and req.body is wmply
There are few problems which i'm facing right now
req.body is empty it is showing {} in console
I am unable to update it
When I hit the endpoint with a PUT request, I'm unable to get the req.body
...
1
vote
1
answer
18
views
Mongoose : find a field by expression
Here is my adresse Schema :
const adresseSchema = mongoose.Schema({
adresseComplete: {
type: String,
required: true,
trim: true,
},
ville: {
type: String,
required: false,
}...
0
votes
0
answers
20
views
GridFS image upload, not able to get files from db
I'm using GridFsStorage with mongoose to upload image files in MongoDB.
now I managed to perfectly upload images and checked it in DB it's present, after that I want to retrieve it and show but do ...
0
votes
0
answers
19
views
Next.Js MongoDb fetching using getServerSideProps returns empty []
I'm using mongo db with mongoose to fetch data from my db.
When using locally I sometimes get the results immediately, but sometimes i need to restart the development server and after that I get the ...
0
votes
0
answers
31
views
How to convert BSON to JSON or Object? [closed]
How to convert BSON to JSON or Object?
this is my way to convert BSON file from dump of MongoDB to Object.
const fs = require("fs")
const BSON = require("bson");
function ...
1
vote
1
answer
25
views
Why populate and exec do not work with aync/await functions?
I have 2 mongoose models Task and User, and I have established a relationship between them. In the task,
I referenced the owner of that task using the ref as follows:
const taskSchema = new Schema({
...
-1
votes
1
answer
63
views
MongooseError: Model.findById() no longer accepts a callback
Hi 👋 i've encountered a problem can anyone help, Thanking you in advance !
MONGOOSE VERSION: "mongoose": "^7.0.3"
MongooseError: Model.findById() no longer accepts a callback at ...
0
votes
2
answers
23
views
Error: The X-Total-Count header is missing in the HTTP Response. | React Admin
I`m trying to fetch posts from "http://localhost:5001/posts".
I'm using react-admin but with my own api, this is the "dataprovider" for the frontend:
import jsonServerProvider from ...
0
votes
0
answers
19
views
What MongoDb/Mongoose method shoud I pick?
based on the image I added, how can I make the updated Documents to be saved and reflect it on the database?
btw I'm using mongoDb
and the scenario is like when I checkout the products on the middle ...
0
votes
0
answers
8
views
can I skip documents in FindOneAndUpdate() that are updating within an active transaction in mongodb
I am implementing pooling flow within socket, and mongodb and I have to use transactions because I have to perform three tasks whenever a ticket is assigned to a person change his busy check to true ...