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,706
questions
0
votes
0
answers
11
views
How to close Mongoose connection when App closes from debugger in VSCode
I'm testing a Node.js project in VSCode but I'm concerned that my Mongoose connection is not closed when I restart using the Debugger.
I use the code below but when I close with the debugger SIGINT ...
1
vote
1
answer
17
views
Mongo Query Collection for String in Array and Push to New Array Nested Object
First and foremost it's been a long time since I've done development, let alone anything with Mongo but I've yet to find a solution to what's likely a simple issue.
In context, I'm trying to get an ID ...
0
votes
0
answers
19
views
DeprecationWarning: The `punycode` module is deprecated
vs code terminal showing deprecation warning
(node:22063) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... ...
-1
votes
0
answers
20
views
Can anyone help me resolve this error? I'm using "next": "^14.0.3", and whenever I try to connect to mongodb I get this error
(node:5748) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
(node:5748) ...
1
vote
2
answers
42
views
It is considered bad practice to use Mongodb ObjectId in the url?
I'm developing a recipe sharing web app using MERN stack, and i was planning to use this kind of url for showing the recipes info
../recipe/:recipeName/:id
I wanted to know if it is a bad practice to ...
1
vote
1
answer
28
views
How to add a specific field into array of objects in mongodb projection
I've a query like below, It joins 3 tables and projects data, the query looks like this.
db.incomedistros.aggregate([
{
$lookup: {
from: "orders",
localField:...
0
votes
1
answer
23
views
Best way to performantly resolve nested GraphQL queries with MongoDB
I am trying to write a resolver which gets the accounts belonging to a customer. The parent.accounts attribute is an array of account_ids. In the code below, I attempt to get an array of accounts for ...
-1
votes
0
answers
23
views
How to convert this Prisma model Schema into mongoose model schema?
I'm trying to build a messenger clone app using next.js 14 . and adding mongoDB database using mongoose. and I'm taking help from a youtube tutorial to build this app. But there, sir used prisma . and ...
0
votes
0
answers
28
views
Mongoose models are not retained after dynamically creating them
I am using nodejs, express and mongoose with MongoDB to create a templated sort of e-commerce platform. I am trying to dynamically create models through post requests using my API. I use a single ...
0
votes
2
answers
35
views
MongoDB Having Multiples Schema Why Is It Choosing Last Schema
I made a architectural decision to use multiple schemas since it is allowed rather than use different database and having to deal with clusters. I have noticed that when using the model rather than ...
0
votes
0
answers
28
views
How can I handle database Models referencing to each other or being shared by different microservices?
I have a monolithic full stack app, that i am trying to refactor to a microservice architecture. In the monolithic architecture, I have the following models:
import mongoose from "mongoose"
...
1
vote
1
answer
58
views
Express mongoose filter array of ids
I have a user schema were it has a role ref which is an array of ids and i want to filter user with role id.
const users = await User.find(
{ roles: { $in: [params.role] } },
"-password"
...
0
votes
2
answers
61
views
How do I update different objects in an array within the same query in mongoose?
This is my mongoose schema:
const humanSchema = mongoose.Schema({
id: String,
person: [
id: String,
age: Number,
sex: String,
height: String
],
...
0
votes
1
answer
34
views
MongoDB not working with delete method when using deleteOne
I'm using node and mongoose to build my first API Restful but I'm having some problems with the "Delete" method.
async function remove(req, res) {
const { id } = req.params
const ...
0
votes
1
answer
40
views
Transaction in mongo with Nestjs do not work
I want to make a transaction and I am using findOneAndUpdate I get the following error: "MongoServerError: Transaction numbers are only allowed on a replica set member or mongos". What I can ...
0
votes
1
answer
20
views
Is it possible to do case-insensitive search on Keys/Fields in MongoDB? with Typescript
For example a way to treat or detect a field "productionYear" in DB against "productionyear".
So can I do caseinsentive search on both fields and values?
1
vote
1
answer
56
views
Mongodb populate without model parameter
I am trying to populate some collection in another collection. However without specifying model in populate method it is not replacing with actual document. Here are my code
cabinet.schema.ts
import {...
0
votes
0
answers
13
views
mongoose virtuals in typescript does not know type of this
Using version 8.0
interface User {
firstName: string;
lastName: string;
}
const UserSchema = new Schema(
{
firstName: String,
lastName: String
},
{
...
1
vote
2
answers
33
views
How do I add a document using mongoose with one field being empty object?
This is my schema:
const wlb_schema = new mongoose.Schema({
wlbId: Number,
wlbName: String,
color: String,
coordinates: Object,
boardId: []
})
I want to add a document using this schema, ...
0
votes
1
answer
36
views
How to populate a populated field name in mongoose
this is my example populated result:
I need to populate the popoluated field name from 'fileInfo'
Inside fileInfo i need to populate the filed name 'createdBy'
{
_id: new ObjectId("...
0
votes
1
answer
70
views
Error while passing an array of IDs of Items to be deleted to the backend using Axios.delete()
I am trying to delete several Items from a database(mongoose) at once by selecting them and clicking a delete button. I have managed to get from the the database the IDs of each element in the list. I ...
0
votes
0
answers
12
views
2dSphere query showing error unknown operator
Im using 2d Sphere to find user data from cosmosDB using mongoose
But i keep getting error `unknown operator: $nearSphere
const userSchemaModel = new mongoose.Schema(
{
contactNumber: {
...
0
votes
1
answer
25
views
How do i resolve module not found errors in mongodb after node upgrade to v18?
I'm getting these warnings after upgrading the node version from 16 to 18, can anyone please tell me what is the fix for these warnings? Do i need to add these dependencies to project?
Package.json
...
2
votes
1
answer
63
views
In Mongoose, add or update a object to an array by field
My model
const mongoose = require('mongoose');
const TelemetrySchema = new mongoose.Schema({
MQTT: {
Id: { type: String, trim: true, required: true },
},
Presets: [{
Id: Number,
...
2
votes
1
answer
44
views
How to combine multiple arrayFilters for a single key
Let's say I have a schema in this format:
const some_schema = new mongoose.Schema({
"id": { type: Number },
"list": [
{
id: { type: Number },
...
0
votes
0
answers
29
views
Optimizing MongoDB Query: Finding Passengers Within a Specified Radius from a Given Point
I have a MongoDB schema as follows:
const passengerSchema = new mongoose.Schema({
socketId: {
type: String,
required: true,
unique: true
},
userId: {
type: ...
2
votes
2
answers
59
views
Delete specific object in array element in document and save mongoose
I want to remove an object from my array. First, I want to find the customer by their ID, and then within the customer model in the array of carts, I want to delete one of the items based on the ID.
...
3
votes
1
answer
48
views
Mongo Aggregate Pipelines - Multiple Lookups in another Collection
I'm having some trouble understanding aggregate pipelines when doing a seemingly complex match up with another collection. The goal is to get a list of videos that a specific user has no ...
0
votes
0
answers
34
views
Querying referenced mongoDB collection with mongoose
My mongoDB document schema for favourite products is currently structured below:
{
_id: ObjectId,
addedBy: ObjectId,
product: ObjectId
}
I am trying to query the product collection referenced ...
0
votes
0
answers
20
views
Mongoose 'pre(save)' hook interfering with save() method
So I am working on the authentication logic for this e-commerce project.
I am using mongoose and validator to verify some fields in my userSchema.
I also have a 'pre('save') that hashes user password ...
0
votes
1
answer
52
views
MongoDB/mongoose: query array field elements to match a part of a string
GIVEN
a searchString "*** test text before string *** john doe | test string after string"
AND
a MongoDB document:
{
"name": "John Doe",
"matchingWords": [
...
-1
votes
0
answers
22
views
Unable to Save Nested Array of Objects in Mongoose Schema
I'm currently facing an issue with saving a Mongoose document with a nested array of objects. The document is getting saved successfully, but the array (areaInfo) is not being stored in the database ...
0
votes
1
answer
25
views
Mongoose Connects, queries but won't return data
I am using the following:
mongodb 7.0 in a vm (ubuntu no container)
nodejs 18+
mongoose 7.5.0
kubernetes 1.28.3
When I run the application in a kubernetes container, the application is able to connect ...
0
votes
0
answers
7
views
lucia-auth mongoose typescript syntax is incorrect lucia.ts
I am very new to TypeScript and to lucia-auth. I was following the documentation's instructions for the Mongoose database adapter, and in the lucia.ts file, I am getting red underlines in VSCode for ...
2
votes
1
answer
29
views
Issue populating mongoose models
I have two models, Pokemon and Attacks. The Pokemon model has an array of moves as strings, which I would like to populate with the Attacks collection using the Attack name as the key.
Pokemon Model
...
-3
votes
0
answers
20
views
How to Populate data from an Excel file to mongoose [closed]
I'm trying to add this data from an excel file to a mongo database. The issues is that there's a record of 20K users data in the file so automating it is the main task. A person might have multiple ...
0
votes
0
answers
16
views
How to automatically update reference models in mongoose by editing/creating documents in the corresponding 'referenced' model?
I have 3 models in my API , Patient, Doctor and Reviews. I have referenced the Reviews model in the Doctor model. The idea is that a patient is able to post a review and rating for a particular doctor ...
-2
votes
1
answer
38
views
Mongoose: filter option in a aggregation query
I'm having problems filtering out data in a query. My original query works, but I get 0 results if I add a match statement at the end of the pipepline (if Base in code). Base is a field in users.
...
1
vote
2
answers
50
views
Aggregate operation is not returning anything with mongoose schema
The main purpose is to get the total price of the orders array of objects. So I used mongoDB aggregation operation. I used NoSQL booster to check query there I can get the totalPrice but when I use it ...
0
votes
1
answer
18
views
NestJs + mongoose ClassSerializerInterceptors not working
I have a project in nestJs, with mongosee, and I want to exclude certain properties from returned object.
Specifically:
@Schema()
export class User {
@Prop({type: String, required: true, unique: ...
0
votes
0
answers
53
views
Unable to connect MongoDB with basic example
I am using the example from the MongoDB website. here is the link to the example. https://www.mongodb.com/docs/drivers/pymongo/
Here is the code in my app.py file.
from pymongo.mongo_client import ...
0
votes
1
answer
52
views
Mongoose Unique is not working , assign the duplicate values
This is my full code where i an trying to validate the data from user
import { Schema, model } from 'mongoose';
import { User } from './user.interface';
const userSchema = new Schema<User>({
...
0
votes
1
answer
24
views
How to get value from pending promise from mongoose model(model.findOne())
I have problem: i cant resolve promise when i need, with this part of code, queries done correct. I use NestJs if it helps. I need it to return a user object.
Here's that i've done so far.
private ...
1
vote
1
answer
35
views
How to directly update reference models in mongodb by creating documents in another model?
Okay so I have 3 models in my API , Patient, Doctor and Reviews. I have referenced the Reviews model in the Doctor model. The idea is that a patient is able to post a review for a particular doctor ...
-1
votes
1
answer
31
views
mongoose schema.create() do not post all schema fields to mongoDb. What am i doing wrong?
So i have a mongo schema as follows;
const mongoose = require('mongoose');
const adressSchema = require('./entities/adress.entities');
const cardSchema = require('./entities/card.entities');
const ...
-1
votes
0
answers
68
views
"Error creating bet: TypeError - Cannot read properties of undefined (reading 'toString')"
Introduction:
I am facing a problem when creating a bet in my Node.js application. The code related to the POST route /api/bets is generating an error that I cannot resolve.
Relevant Code:
Here is the ...
0
votes
0
answers
6
views
error on save for mongoose--userScheema.pre('save')
I am basically getting an eror when i am using userSchema.pre('save',asyn()) in typescript
The exact error is
Error:
No overload matches this call.
The last overload gave the following error.
Argument ...
-2
votes
0
answers
17
views
Connecting my Next js code to Cloud MongoDB [closed]
`Error connecting to MongoDB Error: querySrv ENOTFOUND _mongodb._tcp.cluster0.x7daiyv.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/promises:251:17)
at QueryReqWrap....
0
votes
1
answer
37
views
GraphQL/APOLLO - Cannot query field "field_name" on type "Query"
I am trying to make a query like this in the latest apollo/server 4.9 and graphqlClient - 3.7 like below:
const USER_DATA = gql`
query getUserData($subdomain: String!) {
getUserData(subdomain: $...
2
votes
2
answers
43
views
How to lookup a sub-array in mongodb?
I tried to use aggregate and lookup but look like I cannot keep role in the members item. Any idea how to resolve it?
db.groups.insertMany([
{
title: 'Hi',
members: [
{
...