bwgjoseph / mongoose-vs-ottoman

feature comparison between mongoose and ottoman
0 stars 1 forks source link

[regression?] findOneAndUpdate #73

Closed bwgjoseph closed 3 years ago

bwgjoseph commented 3 years ago

Hi,

While re-running my test suite, I noticed that running findOneAndUpdate seems to not update any of my fields.

These are the setup

const defaultDate = new Date();

const baseSchema = new Schema({
    createdAt: {
        type: Date,
        default: () => defaultDate,
        immutable: true,
    },
    updatedAt: {
        type: Date,
        default: () => defaultDate,
    },
    createdBy: {
        type: String,
        default: () => 'Joseph',
        immutable: true,
    },
    updatedBy: {
        type: String,
        default: () => 'Joseph'
    }
});

const schema = new Schema({
    name: {
        type: String,
        required: true,
    },
    operational: {
        type: Boolean,
        default: true
    },
}).add(baseSchema);

const opt = {
    name: 'hello',
    operational: true,
};

This is the test

const Immutable3Model = ottoman.getModel('immutable3') || ottoman.model('immutable3', schema, { idKey: '_id' });
const schemaData = new Immutable3Model(opt);

const created = await Immutable3Model.create(schemaData);
console.log(JSON.stringify(created, null, 2));
const changeDate = new Date();
const findOneAndUpdate = await Immutable3Model.findOneAndUpdate({ _id: created._id }, {
    name: 'test',
    createdAt: changeDate,
    createdBy: 'Edwin',
    updatedAt: changeDate,
    updatedBy: 'Edwin',
});
console.log(JSON.stringify(findOneAndUpdate, null, 2));

This is the output

// after created
{
  "name": "hello",
  "operational": true,
  "createdAt": "2021-05-07T10:39:14.616Z",
  "updatedAt": "2021-05-07T10:39:14.616Z",
  "createdBy": "Joseph",
  "updatedBy": "Joseph",
  "_id": "21fb0451-60d8-4948-ae89-a8bd75526ff0",
  "_type": "immutable3"
}
// after findOneAndUpdate
{
  "_id": "21fb0451-60d8-4948-ae89-a8bd75526ff0",
  "createdAt": "2021-05-07T10:39:14.616Z",
  "createdBy": "Joseph",
  "name": "hello",
  "operational": true,
  "updatedAt": "2021-05-07T10:39:14.616Z",
  "updatedBy": "Joseph"
}

Thanks

AV25242 commented 3 years ago

@bwgjoseph can you pass the consistency as an option, since it uses N1QL behind the scene it would not be immediately consistent ? Did you check the backend later to see if it got updated. I would start with that first.

bwgjoseph commented 3 years ago

Nope, it does not work. And it shouldn't need to pass in any way since it's a single API call, and the result from this call should give back the correct response without consistency defined

AV25242 commented 3 years ago

Ah ok, will check with dev and get back

AV25242 commented 3 years ago

https://github.com/couchbaselabs/node-ottoman/issues/468

AV25242 commented 3 years ago

This should be fixed with the next release.

httpJunkie commented 3 years ago

Fixed w/ alpha 29

bwgjoseph commented 3 years ago

This is not fixed yet. I'm still getting facing the same issue

ariamF11 commented 3 years ago
const findOneAndUpdate = await Immutable3Model.findOneAndUpdate(
  { _id: created._id },
  {
    name: 'test',
    createdAt: changeDate,
    createdBy: 'Edwin',
    updatedAt: changeDate,
    updatedBy: 'Edwin',
  },
  // { new: true },πŸ‘ˆπŸΌπŸ‘ˆπŸΌπŸ‘ˆπŸΌ To get document updated
);

Please check this: Ottoman findOneAndUpdate doc new option

bwgjoseph commented 3 years ago

Thanks! I missed that, it working now