dimadeveatii / mongo-dot-notation Goto Github PK
View Code? Open in Web Editor NEWTransform objects to MongoDB update instructions
License: MIT License
Transform objects to MongoDB update instructions
License: MIT License
Can you add "$push" for arrays ?
It would be great for this project to provide its own types. I was unable to find type definitions published via npm.
{ 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)
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'
}
}
}
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!!!!
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?
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]]);
}
Great Job!
Any plans to make it available as Meteor package ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.