carbon-io / carbond

MIT License
2 stars 5 forks source link

New Collection semantics #168

Closed willshulman closed 7 years ago

willshulman commented 7 years ago

In carbond:

At same time we should update CarbonClient to return for insert and save (upsert case -- or whatever leafnode does) the object passed in with _id updated.

Wrote this code:

function reconcileId(obj, res) {
  if (res.statusCode === 201) {
    if (!obj._id) {
      if (res.headers) {
        if (res.headers._id) {
          obj._id = EJSON.parse(res.headers._id)
        } else if (res.headers.location) {
          var pArr = res.headers.location.split('/') 
          obj._id = pArr[pArr.length - 1] 
        }
      }
    }
  }
}

which I use in insert and saveObject in collection.js (in carbon-client-js).

BUT... I realize the path in the location header will not have the proper EJSON form of the new _id values. So.... I wonder if we should add an _id header just for CarbonClient (since Carbon Client is the only code that would be setting back an _id on the object passed to the op). We would then EJSON.parse the header value to set the _id back.

willshulman commented 7 years ago

And then we need to add unit tests to carbon-client-js

willshulman commented 7 years ago

Let's also add to InsertObjectConfig a flag called returnInsertedObject that defaults to false. Might also have to change carbon client to do the right thing in both cases.

gregbanks commented 7 years ago

:selfie: f29f4a3