Skip to content

windeko/mongo-copy-field

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Copy Mongo Field

This package will help you in case when you have legacy fields like summ and sum and want to copy value from the legacy to new and delete an old field.

Supporting JS and TS

Below you'll see code fragments for TypeScript, but this module also supports Javascript. Just use it like that:

const MongoCopyField = require('./lib').MongoCopyField

const mc = await MongoCopyField.connect({
    url: ''
})

How to use

There is a bit of tips about how to use this package

Connection

You can use MongoDB connection URL

import { MongoCopyField } from './src'

const mc = await MongoCopyField.connect({
    url: ''
})

Or you can use raw params like that

import { MongoCopyField } from './src'

const mc = await MongoCopyField.connect({
    host: '',
    port: 27017,
    db: 'someDB',
    username: 'someUser',
    password: 'somePassword',
    authSource: 'authDB_if_you_wish',
})

Copying

So, let's assume you wish to copy info from the field avgSumm to avgSum in the averageCollection collection. You can do that and save legacy field like that

mc.copyValues('averageCollection', 'avgSumm', 'avgSum')

Or you can delete legacy field

mc.copyValues('averageCollection', 'avgSumm', 'avgSum', true)

Also works

Package copying all kind of data from/to any desired destination.

For example, you could copy data from 0-level to some information object:

mc.copyValues('comments', 'authorId', 'author._id', true)

Response

copyValues now returns result

const res = mc.copyValues('comments', 'authorId', 'author._id', true)
// { matchedCount: 8658, modifiedCount: 8658, upsertedCount: 0 }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published