update object using mongodb way, also support comment-json
object
👷 Still Working.
Setup via NPM
npm install declaration-update --save
This is a declaration for update a object in Javascript.
// import update from 'react-addons-update';
import { query } from 'declaration-update';
let testStores = {
_id: 1,
fruits: [ "apples", "pears", "oranges", "grapes", "bananas" ],
vegetables: [ "carrots", "celery", "squash", "carrots" ]
}
const change = query(
testStores,
{},
{ $pull: { fruits: { $in: [ "apples", "oranges" ] }, vegetables: "carrots" } }
);
console.log(testStores, change)
/*
testStores: {
"_id" : 1,
"fruits" : [ "pears", "grapes", "bananas" ],
"vegetables" : [ "celery", "squash" ]
}
change: [{op: "$pull", key: "vegetables", value: ["carrots", "carrots"]}]
*/