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

add option to translate all ObjectID fields per record #17

Merged
merged 2 commits into from
Aug 23, 2016
Merged

add option to translate all ObjectID fields per record #17

merged 2 commits into from
Aug 23, 2016

Conversation

crobinson42
Copy link
Member

@crobinson42 crobinson42 commented Aug 23, 2016

#16

  • - tests

@jmdobry
Copy link
Member

jmdobry commented Aug 23, 2016

I personally do not use MongoDB, so can you explain what this PR does? I just want to make sure there aren't any breaking changes.

Also, these changes need tests. (Tests would help explain the expected behavior.)

@crobinson42
Copy link
Member Author

I ran into the need for this feature when starting to implement js-data-mongodb for an API that uses an existing MongoDB database set of data. The other API's in production for this database would set fields that have relation to another record not by simply the string id but by new ObjectID(idString) - when fetching records with js-data using js-data-mongodb I was expecting a record like this:

{
 id: "57bc950fe77ea192aece82d6",
 name: "Cory"
 // a relation field storing the id of the company record
 company:  "57bc9541e77ea192aece82d7"
}

But, instead I was getting this:

{
 id: "57bc950fe77ea192aece82d6",
 name: "Cory"
 // a relation field storing the id of the company record
 company:  {
  _bsontype: "ObjectID", 
  id: "<Buffer 35 37 62 63 39 35 34 31 65 37 37 65 61 31 39 32 61 65 63 65 38 32 64 37>"
 }
}

This PR gives the option to convert any ObjectID bson fields in a MongoDB record to a string id.

You can experiment with the above example in your node console:

const ObjectID = require('bson').ObjectID
console.dir(new ObjectID())

You'll most likely see funny characters on the id field of that object, that's because it's a Buffer object. Anyways, that demonstrates the use and need for this PR.

@jmdobry jmdobry merged commit d386367 into js-data:master Aug 23, 2016
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

Successfully merging this pull request may close these issues.

None yet

2 participants