Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    thug-king
    @thug-king

    Actually the thing is i have been trying to work out the connection of the mongodb server in codesandbox as i am new to it and couldn't find anything?
    when i run my app it shows error and Ibelieve that is due to the mongod command not running
    and when i try to run the mongod command in the terminal it says that no such command exists?
    PLS someone help me

    this is the error i was talking about:
    UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [sandbox:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND sandbox sandbox:27017]
    at Pool.<anonymous> (/sandbox/node_modules/mongodb/lib/core/topologies/server.js:431:11)
    at Pool.emit (events.js:198:13)
    at createConnection (/sandbox/node_modules/mongodb/lib/core/connection/pool.js:559:14)
    at connect (/sandbox/node_modules/mongodb/lib/core/connection/pool.js:973:11) at makeConnection (/sandbox/node_modules/mongodb/lib/core/connection/connect.js:39:11)
    at callback (/sandbox/node_modules/mongodb/lib/core/connection/connect.js:261:5) at Socket.err (/sandbox/node_modules/mongodb/lib/core/connection/connect.js:286:7)
    at Object.onceWrapper (events.js:286:20)
    at Socket.emit (events.js:198:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    (node:687) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
    (node:687) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

    Here is a link to my project:
    https://codesandbox.io/s/yelpcamp-1uh33

    Can someone please help me>
    ?
    ?
    ?
    ?
    ?
    ?
    anyone online?
    Pedro Kehl
    @pedrokehl

    Hey Guys, I have a very specific case.

    This is the following situation:

    Story = {
    "_p_person": {
    type: Schema.Types.ObjectId
    alias: "investor",
    ref: "Person",
    get: (value) => {
    return value.replace('Person$', '');
    },
    set: (value) => {
    if (!value) {
    return value;
    }
    return Person$${value};
    }
    }
    }

    Person = {
    _id: ObjectId
    }

    saved object looks like
    Story = {
    _p_person: 'Person$123'
    }

    Person = {
    _id: '123'
    }

    How can I populate Story with Person object in a query?
    When I try to populate, I have the error Message:
    "If you are populating a virtual, you must set the localField and foreignField options"
    Is it possible to populate using mongoose in this very specific case scenario? Thanks.

    Kev
    @lineus
    @pedrokehl are you getting an error when you save documents with that code? something about your _p_person set function looks off to me. I don't think you'll be able to set that path to a string that starts with Person$ without getting a Validation error.
    Pedro Kehl
    @pedrokehl
    Hey @lineus , the gitter removed the ` symbol in my message, it's using the template string feature.
    But no, I dont have issues saving it
    The layout is very ODD, the reason is that its an existing application that uses Parse Server (with its own ORM system) and I want to migrate to start using mongoose on it, there's still many queries in the system using Parse-Server so I need to keep the retro-compatibility, I cant change the database schema yet.
    Kev
    @lineus
    @pedrokehl I tried to recreate it here with the backticks but I can't save a Story doc. If you like, tweak my example to make saving work and I'll be happy to try and help sort out what's up with population.
    Kev
    @lineus
    @pedrokehl If I change the pathType on _p_person to string, I can save docs, and this allowed me to test out populating here is a working gist
    Pedro Kehl
    @pedrokehl
    Hey Kev
    @lineus , this is a working version, sorry if not clear before
    posted in a gist to make it easier :)
    Pedro Kehl
    @pedrokehl
    LOL, creating this GIST, I just realized that it's possible, I just had to change the path to be '_p_person' that I can change dinamically in an adapter function
    Thanks Kev!
    Kev
    @lineus
    cool, glad I could help. I haven't been here in a while :)
    Pedro Kehl
    @pedrokehl
    the thing was actually the options field that you added in your gist
    cause I tried before with p..., without knowing about that getters parameter, and it was not working
    Thanks a lot :)
    Robert Friedman
    @robfr77
    Need to refactor saving a file as a single map in a mongoose schema to also taking in an array of file objects and saving each as a map, documentation link appreciated
    I’m just going to try a new schema for this alternate mode taking an array of maps
    Harsha MV
    @harshamv_twitter
    How to ensure Mongoose Unique Email Address Validation https://stackoverflow.com/questions/58898066/mongoose-unique-email-address-validation
    hillct
    @hillct
    Good afternoon all. I’ve run into an issue when attempting to set a default value, within a schema plugin, using schema.add as seen here https://pastebin.com/BrukgZig but the default is not being set, for reasons that are unclear to me. Does schema.add not respect element defaults?
    hillct
    @hillct
    It turns out I had currupted data that was yielding this symptom
    cduran85
    @cduran85
    hello, good morning, I'm learning and I have an error:
    Error: Cannot find module '../build/Release/bson'
    I hope you can help me fix it, I'd appreciate it
    hillct
    @hillct
    Good evening all. Is there a mongoose release scheduled, that addresses the DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. ? It appears that ensureIndex is only used within the mongoose in my test case
    hillct
    @hillct
    Came across this issue Automattic/mongoose#8267 which addresses my concern
    fisehara
    @fisehara
    Is there a way to connect a GCP Firestore / Firebase NoSQL database to a mongooose layer?
    We are using nestjs with mongoose and currently run on MongoDB Atlas - as it turns out this services has bad Logging, bad performance and will end up very costly for our services.
    nestdanchia
    @nestdanchia
    kind: "ObjectId"
    message: "Cast to ObjectId failed for value ":5ddd4b870e2c69057447775f" at path "_id" for model "Customer""
    name: "CastError"
    path: "_id"
    stringValue: "":5ddd4b870e2c69057447775f""
    value: ":5ddd4b870e2c69057447775f"
    nestdanchia
    @nestdanchia
    kind: "ObjectId"
    message: "Cast to ObjectId failed for value ":5ddd4b870e2c69057447775f" at path "_id" for model "Customer""
    name: "CastError"
    path: "_id"
    stringValue: "":5ddd4b870e2c69057447775f""
    value: ":5ddd4b870e2c69057447775f" .............recibida petición: /api/delete/:5ddd4aef4f9a5018accb90a5
    ObjectId(":5ddd4aef4f9a5018accb90a5")
    recibida petición: /api/delete/:5ddd4b870e2c69057447775f
    ObjectId(":5ddd4b870e2c69057447775f")................{
    _id: 5ddd4b870e2c69057447775f,
    id: '2',
    name: 'YuYu',
    done: false,
    __v: 0
    },................
    I solve gracias!!!! let customerSchema = new Schema({
    _id: String,
    id: String,
    name:String,
    done:Boolean
    })
    pbaumer2
    @pbaumer2
    Good afternoon all! I have added a new field to a document, it is an ObjectId and the default should refer to a certain object. How can I add such smart defaults?
    Jasmin Mustafic
    @J-Mustafic
    someField: {
        type: Schema.Types.ObjectId,
        ref: 'SomeOtherField',
        default: '5ddbe52428d9e76752c38172',
      }
    @pbaumer2
    Maybe this could work?
    Jasmin Mustafic
    @J-Mustafic

    Hi All. How can I say to mongoose not to return fields that are not in Schema?

    For example I have user that has name, username and password. And I store few users in database with those 3 fields. After a while I change schema to only have username and password, name is out. Mongoose still returns the name if it is stored in database.

    I know I can query and then ask just for certain fields, but I can't solve my challenge with that approach since I have no idea what fields I want to return or not. I dynamicly change schema sort of. At runtime I remove some fields from schema depending on number of modules that I want to include. So sometimes I will have all fields, sometimes only few.

    Jasmin Mustafic
    @J-Mustafic
    With strict: true field will not be persisted if that field does not exit in Schema, but seems that it does not work other way around.
    Jasmin Mustafic
    @J-Mustafic

    Hi everyone. Me again. I figured out the question above. I used schema.remove() to remove fields from mongoose schema and when i fetch data i use .select(Object.keys(Machine.schema.paths)).

    Now the challenge that I am facing is, that the populate returns null for a field that is removed form the schema.

    For example I have author object field that is remove. And if I don't call populate and fetch the data, author field does not exist which is what I need. But if I call .populate('author'), author field gets value of null. Even though it is missing from schema, I still get it as null when I query. Can this be avoided?

    Logan Valentine
    @krandom
    Hi ppl!! Quick question hopefully someone can advice, I got a working query that looks like this, let constant = await constantsSchema.findOne({ slug, values: { $elemMatch: { name, app }}}); How do I do if I want to find matches where app can be either app or null?
    Logan Valentine
    @krandom
    basically id like to do , values: { $elemMatch: { name, app: (app || null) }}}); but that don't work
    flufsor
    @flufsor
    Hi, newbie question here but what is the correct way to add multiple objects of the same kind of simple object (number and string) in my schema. So i can define my object once and add it multiple times without repeating the same object structure?
    Yogesh Bansal
    @yogeshbansal
    MongoNetworkError: failed to connect to server [cluster0-shard-00-00-iocwy.mongodb.net:27017] on first connect [MongoNetworkError: connection timed out]
    I am trying to connect localhost
    it get connected successfully, when i start the server
    but after hitting a endpoint from client app, it showing this error
    jorgelopezowd
    @jorgelopezowd
    @/all some example how to make a aggregate with dates $gte and $lte, I have problem with timezone, making same query direct in DB works, but using mongoose, it doesn't