Giter VIP home page Giter VIP logo

mongo-dot-notation's People

Contributors

antony avatar dimadeveatii avatar evanshortiss avatar garrows avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

garrows schwing sr4p

mongo-dot-notation's Issues

TypeError in your package ?

{ id: '58751ab0b01f73441d416c3b',
  physicalDescription: 
   { title: 'description title',
     location: { address: 'aaaaaaaaaa', city: 'aaaaaaaaaa', country: 'France' },
     owners: [ [Object] ],
     kind: 'house',
     surface: { total: 69, effective: 50 } } }

I tried using this, however . . .

TypeError: Cannot read property 'name' of undefined
    at isPrimitive (/home/rory/dev/weezhome/api/node_modules/mongo-dot-notation/index.js:53:19)
    at flatten (/home/rory/dev/weezhome/api/node_modules/mongo-dot-notation/index.js:19:7)
    at /home/rory/dev/weezhome/api/node_modules/mongo-dot-notation/index.js:43:5
    at Array.forEach (native)
    at flatten (/home/rory/dev/weezhome/api/node_modules/mongo-dot-notation/index.js:41:8)
    at module.exports.flatten (/home/rory/dev/weezhome/api/node_modules/mongo-dot-notation/index.js:14:3)
    at _callee5$ (/home/rory/dev/weezhome/api/src/schema/property.js:174:24)
    at tryCatch (/home/rory/dev/weezhome/api/node_modules/regenerator-runtime/runtime.js:64:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/home/rory/dev/weezhome/api/node_modules/regenerator-runtime/runtime.js:355:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/home/rory/dev/weezhome/api/node_modules/regenerator-runtime/runtime.js:116:21)

Meteor package

Great Job!
Any plans to make it available as Meteor package ?

[Query] How would I flatten an array inside an object?

Hi,
This is not an issue. I'd just like to know if this is possible:

I have an object:

{
"ipv4": {
         "enable": "yes",
         "rule": [
             {
                "flow": {
                    "destinationAddress": "0.0.0.0"
                }
            }
        ]
    }
}

I'm looking to produce an output like:

{
       ipv4.enable: yes,
       rule.0.flow.destinationAddress: 0.0.0.0
}

Is this possible?

Enhancement request: Change dots in key name to \u2024 while using flatten

I think the subject says it all.
When the key name has a dot, using flatten before mongodb.update() will use the first part as the parent of the second part.
The common thing to do it to replace it with this special char which is also a dot: \u2024.
Ref: https://stackoverflow.com/questions/8429318/how-to-use-dot-in-field-name

After testing, the only code change is replacing the following loop in the lib/flatten.js:

  for(let i = 0, n = keys.length; i < n; i++){
    const key = keys[i] && keys[i].replace(/\./g, '\u2024');
    const newPrefix = !propertyName ? key : (propertyName + '.' + key);
    flatten(updateData, newPrefix, propertyValue[keys[i]]);
  }

Types

It would be great for this project to provide its own types. I was unable to find type definitions published via npm.

How to update multiple objects inside of array?

I have the following schema with an array of objects:

{
    "id": "",
    "email": "",
    "name": "",
    "partnerId": "",
    "picture": "",
   "birthYear": "",
    "address": [
  {
    "id": "6077028c7b15d003327055fa",
    "nickname": "asdasdasdasd",
    "recipient": "assaasasa",
    "phoneNumber": "01088919213",
    "address": "two asdadsasdasdasd",
    "addressDetail": "more addxxxxxress",
    "default": false
  }
 ]
}

I need to update mutiple fields of the object inside of the array:

const input =  {
        "id": "6077028c7b15d003327055fa",
        "recipient": "ttttt",
     	"nickname": "new nic",
    	"addressDetail": "new address"
}

I tried to you your library as follows:

const parsedInput = $.flatten({ address: input });

but received this parsed docs, which updates the fields but set the others to null :(

{
  '$set': {
     'address.$': {
       nickname: 'new nic',
       recipient: 'ttttt',
       addressDetail: 'new address'
     }
   }
}

this is what I think it should work, is there anyway for doing that with your library?

{
  '$set': {
      'address.$.nickname': 'new nic',
       'address.$.recipient': 'ttttt',
       'address.$.addressDetail': 'new address'
     }
   }
}

I love this library

No issue. It's the abs BEST way to do JS / Mongo work..... This needs to be part of their Node SDK. LOVE IT!!! THANKS!!!!

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.