Skip to content

quick-sort/mongobj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongObj

MongObj is a Mongo-style api to update javascript object.

Example

import mongobj from 'mongobj'
let person = {
    "addresses": [
    {
        "country": "China",
        "city": "Shanghai",
        "street": [{
            "road": "Century Avenue",
            "room": "#201",
        }, {
            "road": "People Rd",
            "room": "#101"
        }]
    },
    {
        "country": "USA",
        "city": "Palo Alto"
    }
    ]
}
mongobj.update(person, {
    "$set": {
        "addresses.$[i].city": "Beijing"
    }
}, {
    "arrayFilters": [{"i.country": "China"}]
})

mongobj.update(person, {
    "$pull": {
        "addresses.$[i].street": { "road": "Century Avenue" }
    }
}, {
    "arrayFilters": [{"i.country": "China"}]
})

mongobj.update(person, {
    "$push": {
        "addresses": {
            "country": "France",
            "city": "Pairs"
        }
    }
})
mongobj.update(person, {
    "$unset": {
        "addresses.$[i].street": ""
    }
}, {
    "arrayFilters": [{"i.country": "China"}]
})
console.log(person)

About

Object operation in Mongo-style

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published