Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    robin
    @RobinYang11
    hi all ! can someone helle me ,
    Tijn Hoftijzer
    @112batman
    I get a 401 error Error: Unexpected server response: 401 at ClientRequest.<anonymous> (/home/arch/Desktop/projects/Vibe2/node_modules/ws/lib/websocket.js:604:7) at ClientRequest.emit (node:events:369:20) at ClientRequest.emit (node:domain:470:12) at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:643:27) at HTTPParser.parserOnHeadersComplete (node:_http_common:129:17) at Socket.socketOnData (node:_http_client:509:22) at Socket.emit (node:events:369:20) at Socket.emit (node:domain:470:12) at addChunk (node:internal/streams/readable:313:12) at readableAddChunk (node:internal/streams/readable:288:9) at Socket.Readable.push (node:internal/streams/readable:227:10) at TCP.onStreamRead (node:internal/stream_base_commons:190:23) when connecting to the mongodb server using mongoose. I confirmed I'm using the correct username/password/authSource and it does work when connecting using robo3t. Does anyone know how I can solve this
    Richard Bateman
    @taxilian
    that error isn't coming from mongoose
    it's a websocket error
    Tijn Hoftijzer
    @112batman
    Ok... Where do I ask for support? @taxilian
    Richard Bateman
    @taxilian
    ?? the error has nothing to do with mongoose
    or mongodb
    so... google? a colleague or mentor? Someone who knows node.js?
    this is a "your code is broken, figure out where and why" problem, it's not a "you need help with a specialized library" problem
    Ario K
    @itsario_twitter

    I've implemented a mongoose setter: https://mongoosejs.com/docs/tutorials/getters-setters.html

    For some reason, I'm noticing the setter is getting hit on a .find query. Is that normal?

    doh!
    Ario K
    @itsario_twitter
    what a weird change
    what is the point of running a setter on a find query
    control
    @control_:matrix.org
    [m]

    Hi Fellow Mongoosers, I'm running into an issue and I wondering if anyone can offer insight:

    • I have a Mongoose Model with a static declared, this static is async.
    • The static is returning this.find().orFail(...);
    • I wanted to be able to use the return value from this static to modify the Query object (i.e. .where(), .select(), ...)
    • Because the static is async (I need to do some async/await inside) when I resolve the returning promisse, instead of having the Query object I have the full executed Query

    Any insight on I would be able to just return the Query object without executing ?

    control
    @control_:matrix.org
    [m]

    :point_up: Edit: Hi Fellow Mongoosers, I'm running into an issue and I was wondering if anyone can offer insight:

    • I have a Mongoose Model with a static declared, this static is async.
    • The static is returning this.find().orFail(...);
    • I wanted to be able to use the return value from this static to modify the Query object (i.e. .where(), .select(), ...)
    • Because the static is async (I need to do some async/await inside) when I resolve the returning promisse, instead of having the Query object I have the full executed Query

    Any insight on I would be able to just return the Query object without executing ?

    AverageDJSLearner
    @AverageDJSLearner
    Hi.
    bilalesi
    @bilalesi
    Hi, i am running in a new feature for my startup, and i want to build robust secure sub-module of our main app, my app is for healthcare industry, and we want to encrypt the data of our client's patients so i see that mongo has implement such a feature CSFLE and i want to know if by any chance mongoose offer this option, and is there any docs (i can't find in the official www) that's can help
    Alejopdp
    @Alejopdp
    Hi everyone! ended up here because i need to do a specific query and i'm not being able to find any useful resource about how to do it
    i would like to get an array of documents from my database by searching them with an array of dates
    i read that you cannot query the database using a date equality and you should use $gte and $lte
    but i don't know how to implement it when using an array of dates
    the following query obviously doesn't work but it helps to understand what i'm trying to do
    MyModel.findBy(
    {
    dateField: arrayOfDates
    })
    UchihaYuki
    @UchihaYuki

    Hi,
    My user documents have the following structure:

    {
      name: "Tom",
      rights: {
        vip: "2021-07-12T08:13:12.966Z",  
        admin: "2022-07-12T08:13:12.966Z"
      }
    }

    Is it possible to query all user documents who has an expired right? And is it possible to build index on rights' keys?

    Edit:
    The key of rights is not fixed, we don't known the name of right in advance.

    4 replies
    Cody Hageman
    @CodyWHageman
    Hey guys, does mongoose support Amazon DocumentDB (with mongodb compatability)
    Sorry if this has been asked before lol
    Richard Bateman
    @taxilian
    pretty sure that mongoose only supports mongodb
    Bar
    @barintsights
    Hi, what are the best practices of keeping the caller on the call stack to mongoose errors? in this case, when adding .exec(), mongoose adding the caller to the stack. but what happens when executing Model.insertMany which doesn't accept exec() for instance?
    David Ho
    @1073113
    export const ProductSchema = new Schema({
    productTitle: { type : string },
    productOwner: { type: mongoose.Schema.Types.ObjectId }
    })
    In this producOwner field , would it be necessary to insert Index : true for querying purposes?
    Nikola-Milovic
    @Nikola-Milovic
    Hey guys, can anyone check out this issue having hard time implementing references to other documents, having some real weird behaviours
    Gayathri Selvaraj
    @gayaselva01_twitter
    Hey guys, does mongoose support mongodb v5 time series?
    If yes, can someone send the link to that doc? Or some sample to create time-series collection using mongoose
    Caleb Cox
    @canac
    @vkarpov15 I'm working on the PR for #10628 we discussed. Can you help me understand the difference between _fields and _userProvidedFields? Under what circumstances would they differ?
    Silviu Bogan
    @silviubogan

    Hello! I use the latest stable version of TS, 4.4.2, and the latest stable version of Mongoose, 6.0.2, (I upgraded both today) and I get the following error besides other errors which I can deal with. With this one, I don't know what to do.

    error TS2322: Type '{ type: (typeof Schema.Types.ObjectId)[]; ref: string; }' is not assignable to type 'typeof SchemaType | Schema<any, any, any> | Schema<any, any, any>[] | readonly Schema<any, any, any>[] | Function[] | SchemaTypeOptions<ObjectId[]> | ... 5 more ... | undefined'.
      Types of property 'type' are incompatible.
        Type '(typeof ObjectId)[]' is not assignable to type 'Schema<ObjectId, Model<ObjectId, any, any>, {}>[] | readonly Schema<ObjectId, Model<ObjectId, any, any>, {}>[] | Schema<...>[] | readonly Schema<...>[] | undefined'.
          Type '(typeof ObjectId)[]' is not assignable to type 'Schema<ObjectId, Model<ObjectId, any, any>, {}>[]'.
            Type 'typeof ObjectId' is missing the following properties from type 'Schema<ObjectId, Model<ObjectId, any, any>, {}>': add, childSchemas, clone, eachPath, and 36 more.

    The line with the error is: media: { type: [Schema.Types.ObjectId], ref: "Upload" },

    Is this a bug in Mongoose?

    Any help is greatly appreciated.

    Silviu Bogan
    @silviubogan
    The media field in the interface is declared:
    media: mongoose.Types.ObjectId[];
    Michael Cole
    @MichaelJCole
    Hey, thanks for mongoose!
    shrim167
    @shrim167
    Hi ,
    How to make backward compatibility in mongodb using mongoose library
    fuxsocy.py
    @ergiss:matrix.org
    [m]

    Hello everyone, I am doing this query : find({ status: state }, { _id: 0, id: 1 }) which returns me

    [
      {
        "id": "d57fed2d-bd9e-4db9-a6d0-baa9802eb191"
      },
      {
        "id": "9683cb5e-316f-42f4-b48e-2902f964e845"
      },
      {
        "id": "38f8cded-efdb-4650-8ced-489e0641118f"
      },
      {
        "id": "6dd036d6-3379-4bbc-896d-d106fcc8dad0"
      },
      {
        "id": "e8d6cae9-22f0-413d-93df-1db399f43f84"
      },
      {
        "id": "e968439c-f6cd-4eaa-952c-9b7a845965bc"
      },
      {
        "id": "af03dbc3-e8d7-4cae-b6a6-9f46920a3447"
      },
      {
        "id": "5a55c226-e97f-4424-b5ab-6d91872d9ac1"
      },
      {
        "id": "49962d06-3cbc-4372-a2d5-47016cecdd66"
      },
      {
        "id": "80cc927c-f263-4dfc-bb6f-2c12399af7f3"
      },
      {
        "id": "27c6e665-cdd0-47a3-979c-88eee7dd72c4"
      }
    ]

    What I want to achieve is

    [
        {
          "id": "d57fed2d-bd9e-4db9-a6d0-baa9802eb191",
          "id": "9683cb5e-316f-42f4-b48e-2902f964e845",
          "id": "38f8cded-efdb-4650-8ced-489e0641118f",
          "id": "6dd036d6-3379-4bbc-896d-d106fcc8dad0",
          "id": "e8d6cae9-22f0-413d-93df-1db399f43f84",
          "id": "e968439c-f6cd-4eaa-952c-9b7a845965bc",
          "id": "af03dbc3-e8d7-4cae-b6a6-9f46920a3447",
          "id": "5a55c226-e97f-4424-b5ab-6d91872d9ac1",
          "id": "49962d06-3cbc-4372-a2d5-47016cecdd66",
          "id": "80cc927c-f263-4dfc-bb6f-2c12399af7f3",
          "id": "27c6e665-cdd0-47a3-979c-88eee7dd72c4"
        }
      ]
    Is there a way mongoose can help me with this?
    fuxsocy.py
    @ergiss:matrix.org
    [m]
    Solution: I did put the contents of find to a const and then did
    return const.map(element => element.id)
    shrim167
    @shrim167
    Hello everyone , i have created some schema and inserted some data to mongodb, but now i have changed shema ,but i need old schema and new schema should work , so how do i handel this is mongoose
    hillct
    @hillct
    In previous releases of Mongoose, it could be relied upon that an object creatd as follows: var transaction = {
    _id: mongoose.Types.ObjectId(), oherPropery: ‘hasValue’ } could be puhed onto a subdocument array, and saved, and it would have the _id value esablishd prior to the save. It seems this is no longer the case, with the newest release. What’s the proper new mechanism for achieving this objective of defining a valid (uuid compliant) document ID, available for use before the save?
    khurshidkhan99999
    @khurshidkhan99999
    How would I connect to Mongodb using SSL certificate with mongoose@6.0.5 and Nodejs 14.x?

    MongoDB shell version is v5.0.2

    Before updating Mongoose everything was working fine but now it is showing me error in mongoose latest version. Thus I have to update mongodb and node also. I have successfully setup SSL certificate and configure the mongod.conf file also. so I am able to access mongo shell through SSL certificates but my goal is connect through nodejs using mongoose.

        // this is my code but its giving me an error                                                                                                                                                                         
        var fs = require('fs')
        var mongoose = require('mongoose')
        var user_name = 'emailAddress=user@myemail.com,CN=127.0.0.1,OU=UNIT,O=DEMO,L=city,ST=test,C=AU'
    
        mongoose.connect("mongodb://localhost:27017/admin?ssl=true&tlsInsecure=true",
            {
                useNewUrlParser: true,
                useUnifiedTopology: true,
                sslValidate: false,
                auth: { authMechanism: "MONGODB-X509", authSource: '$external'},
                sslCA: fs.readFileSync(__dirname +'/my.crt','utf-8'),
                sslCert: fs.readFileSync(__dirname +'/user.crt','utf-8'),
                sslKey: fs.readFileSync(__dirname +'/user.pem','utf-8')
            })
            .then((res) => {
    
        console.log("connected to the database",res);
        mongoose.Promise = global.Promise;
        const customerSchema= new mongoose.Schema({ name: String,address: String,email:String,});
    
        const Customer= mongoose.model('Customer',customerSchema);
    
        async function createNewCustomer() {const customer= new Customer({name: 'new customer',address: 'new address',email: 'customer1@new.com',});const result = await customer.save();console.log(result);
        }
        createNewCustomer();
    
    
        })
        .catch((err) => {console.log(err)});
    cicpa79
    @cicpa79

    Hi all. Is possible in mongoose execute a native query like this

    db.getCollection("mycollection").insert({
      idCustomer: "aa",
      process: "aa",
      createdAtTimestamp: new Timestamp(),
      createdAtDate: new Date(),
    });

    I need the mongo db newDate() like now in sql.
    If is not possible there is another driver thah can i use?