1.0.0 • Published 8 years ago

prefix-keys v1.0.0

Weekly downloads
275
License
ISC
Repository
github
Last release
8 years ago

prefix-keys

Take all the key-value pairs in an object and return a new object with the keys prefixed.

Useful for updating nested documents in MongoDB

install

    npm install --save prefix-keys

Use

"use strict";
var prefixKeys = require("prefix-keys");

var data = {
    country: "CA",
    province: "ON"
};

var update = {
    $set: prefixKeys("location.", data)
};

var query = {
    _id: userId
};

db.users.update(query, update);