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

Added mongoKeys hook. #348

Merged
merged 2 commits into from
Feb 3, 2018
Merged

Added mongoKeys hook. #348

merged 2 commits into from
Feb 3, 2018

Conversation

eddyystop
Copy link
Collaborator

Wraps mongodb foreign keys in ObjectID

const { ObjectID | = require('mongodb');
const keyFieldNames = ['_id', 'authorId', 'postId'];

{ before: {
  find: mongoKeys(ObjectID, keyFieldNames)
} };
keys= a
from= { a: '111111111111', c: '000000000000' }
  to= { a: 313131313131313131313131, c: '000000000000' }

keys= a
from= { a: { b: '000000000000' }, c: '000000000000' }
  to= { a: { b: '000000000000' }, c: '000000000000' }

keys= a
from= { a: { '$in': [ '111111111111', '222222222222' ] },
  c: '000000000000' }
  to= { a: 
   { '$in': [ 313131313131313131313131, 323232323232323232323232 ] },
  c: '000000000000' }

keys= b
from= { b: '111111111111', c: '000000000000' }
  to= { b: 313131313131313131313131, c: '000000000000' }

keys= [ 'a', 'b' ]
from= { a: '111111111111', b: '111111111111', c: '000000000000' }
  to= { a: 313131313131313131313131,
  b: 313131313131313131313131,
  c: '000000000000' }

keys= a.x
from= { a: { x: '888888888888' } }
  to= { a: { x: 383838383838383838383838 } }

keys= [ 'b', 'a.x' ]
from= { '$or': [ { a: { x: '888888888888' } }, { b: '555555555555' } ] }
  to= { '$or': 
   [ { a: { x: 383838383838383838383838 } },
     { b: 353535353535353535353535 } ] }

keys= [ 'a', 'a.x' ]
from= { '$or': [ { a: { x: '888888888888' } }, { a: '555555555555' } ] }
  to= { '$or': 
   [ { a: { x: 383838383838383838383838 } },
     { a: 353535353535353535353535 } ] }

@eddyystop eddyystop merged commit 907c0ce into master Feb 3, 2018
@eddyystop
Copy link
Collaborator Author

Published in v4.5.0

@eddyystop
Copy link
Collaborator Author

Its debateable whether _id should be included in the foreign keys list. the feathers-mongo adapter wraps _id already. On the other hand wrapping an already wrapped key should work properly.

?????

@ninique
Copy link

ninique commented Feb 3, 2018

If you are not using MongoDB, it is throwing errors when starting the app

@eddyystop
Copy link
Collaborator Author

eddyystop commented Feb 3, 2018

Dare I suggest you not use it for non-MongoDB services?

{edit} Oops, I think I understand what you are saying. Fixing.

@eddyystop
Copy link
Collaborator Author

Fix published as v4.5.1. Sorry about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants