Giter Site home page Giter Site logo

Comments (6)

doowb avatar doowb commented on June 5, 2024 1

Will you do console.log(Object.keys(subdocument)); before sending the subdocument to omitEmpty?

from omit-empty.

doowb avatar doowb commented on June 5, 2024 1

Does it have anything with boolean values on this specific document. I never faced it on other cases.

I don't know, but I think it's a value that MongoDB (or mongoose if you're using that as an ORM) puts on there to track if updates need to be sent to the database.

Depending on the library that you're using to access MongoDB, there should be a way to get just the JSON object from the "model instance" (I don't know what else to call that object). That object will probably be one that you can use to pass to omitEmpty.

I'm going to close this issue since it's not a bug in omit-empty. Feel free to open a new issue if you do find something else in omit-empty.

from omit-empty.

omidmaldar avatar omidmaldar commented on June 5, 2024 1

Ok, I found it. I should have used .toJSON() This the output of Mongodb that have this additional key. If I use subducument.toJSON() then the $init disapears from it. See here for example: https://spectrum.chat/mongodb/general/what-is-init-trying-to-pull-out-array-of-key-names-from-nested-object~91b2f6df-fd61-411d-8be3-cda6b3afdf9b

Thank you for your answer and help @doowb.

from omit-empty.

doowb avatar doowb commented on June 5, 2024

I just installed the latest version from NPM and ran the code above and I don't see the $init: true being output:

image

Are you passing in a plan object? Or are you passing in an object that was created by something else that might have the $init property on it?

from omit-empty.

omidmaldar avatar omidmaldar commented on June 5, 2024

I'm using version 1.0.0 and yes, the object I'm sending to omitEmpty is a subdocument which is returned by MongoDB. The subdoc/object has 6 fields all of Boolean type. I checked the output of Mongo on its find query as well as the original doc in db. None of them has the $init. It's added to object after passing it to omitEmpty.

from omit-empty.

omidmaldar avatar omidmaldar commented on June 5, 2024

I did. I confirm that the $init is there before sending to omitEmpty. This is interesting, $init is there when I use console.log(Object.keys(subdocument)); but not when I simply use console.log(subdocument);
Does it have anything with boolean values on this specific document. I never faced it on other cases.

from omit-empty.

Related Issues (6)

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.