Giter VIP home page Giter VIP logo

node-mongo's People

Contributors

anorsich avatar ezhivitsa avatar nrt3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nrt3 ejaz-ventega

node-mongo's Issues

Why `findOneAndUpdate` function emits `created` event?

https://github.com/auxilincom/node-mongo/blob/master/src/MongoService.js#L188

findOne method returns null if it doesn't match any documents. In that case we emit created event with doc === null. Why does findOneAndUpdate function emit created event? Maybe it is OK when options.upsert is provided, but definitely not in the case of doc === null.

findOneAndUpdate(query, update, options = { returnOriginal: false }) {
    let originalDoc;
    return this.findOne(query) // return null
      .then((doc) => {
        originalDoc = doc; // originalDoc === null

        return this._collection.findOneAndUpdate(query, update, options); // return null
      })
      .then((doc) => { // doc === null
        if (originalDoc) { // skipped
          this._bus.emit('updated', {
            doc,
            prevDoc: originalDoc,
          });
        } else {
          this._bus.emit('created', { // why?
            doc, // doc === null
          });
        }

        return doc;
      });
  }

Bad stack trace for error

With node-mongo we usually get not very helpful stack trace, like this one:

 level:  "error"   
  message:  "MongoServiceError: Document not found while updating. Query: {"_id":"5cc4a6f9361f3f0012151b4c"}
    at MongoService.update (/app/node_modules/@auxilin/node-mongo/src/MongoService.js:123:13)
    at process._tickCallback (internal/process/next_tick.js:68:7)"   
  timestamp:  "2019-04-29T06:38:49.924Z"   

How do we improve it to show where this error has happened?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.