MongoStorageAdapter.findOneAndUpdate returns Parse Object (#3053) (#3064)

This commit is contained in:
Glen Tregoning
2016-11-20 06:02:49 -08:00
committed by Florent Vilmart
parent 4ea455b20a
commit 1eff210a51
2 changed files with 50 additions and 2 deletions

View File

@@ -149,7 +149,7 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
});
});
it('handles array, object, date', (done) => {
it('handles creating an array, object, date', (done) => {
let adapter = new MongoStorageAdapter({ uri: databaseURI });
let obj = {
array: [1, 2, 3],
@@ -189,4 +189,52 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
done();
});
});
it("handles updating a single object with array, object date", (done) => {
let adapter = new MongoStorageAdapter({ uri: databaseURI });
let schema = { fields: {
array: { type: 'Array' },
object: { type: 'Object' },
date: { type: 'Date' },
} };
adapter.createObject('MyClass', schema, {})
.then(() => adapter._rawFind('MyClass', {}))
.then(results => {
expect(results.length).toEqual(1);
let update = {
array: [1, 2, 3],
object: {foo: 'bar'},
date: {
__type: 'Date',
iso: '2016-05-26T20:55:01.154Z',
},
};
let query = {};
return adapter.findOneAndUpdate('MyClass', schema, query, update)
})
.then(results => {
let mob = results;
expect(mob.array instanceof Array).toBe(true);
expect(typeof mob.object).toBe('object');
expect(mob.date.__type).toBe('Date');
expect(mob.date.iso).toBe('2016-05-26T20:55:01.154Z');
return adapter._rawFind('MyClass', {});
})
.then(results => {
expect(results.length).toEqual(1);
let mob = results[0];
expect(mob.array instanceof Array).toBe(true);
expect(typeof mob.object).toBe('object');
expect(mob.date instanceof Date).toBe(true);
done();
})
.catch(error => {
console.log(error);
fail();
done();
});
});
});

View File

@@ -310,7 +310,7 @@ export class MongoStorageAdapter {
const mongoWhere = transformWhere(className, query, schema);
return this._adaptiveCollection(className)
.then(collection => collection._mongoCollection.findAndModify(mongoWhere, [], mongoUpdate, { new: true }))
.then(result => result.value);
.then(result => mongoObjectToParseObject(className, result.value, schema));
}
// Hopefully we can get rid of this. It's only used for config and hooks.