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

Can't use modifiers in update method after upgrade to 2.6.1 #59

Closed
exah opened this issue Mar 26, 2017 · 6 comments
Closed

Can't use modifiers in update method after upgrade to 2.6.1 #59

exah opened this issue Mar 26, 2017 · 6 comments

Comments

@exah
Copy link

exah commented Mar 26, 2017

Steps to reproduce

Use update method in nedb service with modifiers (like $push, $pull, etc.).

projectsService.update('projectId', { $push: { 'data.caption': '' } )

Produces error when using [email protected].

Error: You cannot mix modifiers and normal fields

System configuration

Module versions: 2.6.1

NodeJS version: 6.9.5

Operating System: macOS 10.12 / docker node:6 container

Module Loader: [email protected]


Working normally @2.6.0.
Somehow related to this: v2.6.0...v2.6.1#diff-1fdf421c05c1140f6d71444ea2b27638

@daffl
Copy link
Member

daffl commented Mar 26, 2017

Fixed in v2.6.1

@exah
Copy link
Author

exah commented Mar 27, 2017

Thanks!

@bugss
Copy link

bugss commented Apr 4, 2017

use nedb you can not do this

yourService.update(id, {
        $inc: {
          good: 1
        },
        createdAt:new Date()
      })

property name start with $ and property name not start with $ Can not appear at the same time

so when you set a hooks like this

exports.before = {
  all: [],
  find: [],
  get: [],
  create: [hooks.setCreatedAt(), hooks.setUpdatedAt()],
  update: [hooks.setUpdatedAt()],
  patch: [],
  remove: []
};

and some where just call the below code with the before hook above will always exception(You cannot mix modifiers and normal fields)

yourService.update(id, {
        $inc: {
          good: 1
        }
      })

if you want add timestamp . just remove the hook but set timestampData to true

const db = new NeDB({
    filename: path.join(app.get('nedb'), 'posts.db'),
    autoload: true,
    timestampData: true
  });

I think it's a good idea to put these into a document

@marshallswain
Copy link
Member

@bugss absolutely. Would you mind making a PR to the auk docs?

It's this page: https://docs.feathersjs.com/v/auk/api/databases/nedb.html
which is here in the repo: https://github.com/feathersjs/feathers-docs/edit/auk/api/databases/nedb.md

@bugss
Copy link

bugss commented Apr 5, 2017

feathersjs-ecosystem/docs#457
just add the default config timestampData: true .
Should be able to reduce the possibility of reporting this exception

@pirsplus
Copy link

I don't know if that could help you to solve the issue and pull a new request.

In nedb, if you do this :

db.collection.update({ _id: 'MYID'  },  { key: 'value' , $push: { key: 'value' } }, { returnUpdatedDocs: true, multi: false }, (err, num, doc) => {
  // Error: You cannot mix modifiers and normal fields
})

But, if you use 2 modifiers $set and $push (or whatever)

db.collection.update({ _id: 'MYID'  }, { $set: { key: 'value' }, $push: { key: 'value' } }, { returnUpdatedDocs: true, multi: false }, (err, num, doc) => {
  // will be ok
})

The trick is to use $set everytime and you could add any modifiers you want.

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

5 participants