Skip to content

createId: collectionName vs collection #21

@AndreasChristianson

Description

@AndreasChristianson

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions