Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createId: collectionName vs collection #21

Open
AndreasChristianson opened this issue Apr 28, 2020 · 0 comments
Open

createId: collectionName vs collection #21

AndreasChristianson opened this issue Apr 28, 2020 · 0 comments

Comments

@AndreasChristianson
Copy link

The documentation for createId indicates that it will be passed the collectionName and the item for which an id is being generated. It appears that it is actually passed the collection, as opposed to the collectionName. See

createId: function (collection, doc) {

example:

import low from 'lowdb'
import FileSync from 'lowdb/adapters/FileSync'
import lodashId from 'lodash-id'
import shortId from 'shortid'

const adapter = new FileSync('../../db.json')

const db = low(adapter)
db._.mixin(lodashId)
db._.createId = (collectionName) => {
  console.log(collectionName) // I expect collectionName to be 'sprockets'. Instead it is `[]`
  return `${collectionName}-${shortId.generate()}`
}

db.defaults({
  sprockets: []
}).write()

db.get('sprockets').upsert({ name: 'my sprocket' }).write()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant