Skip to content

Commit

Permalink
MongoStorageAdapter.findOneAndUpdate returns Parse Object (parse-comm…
Browse files Browse the repository at this point in the history
  • Loading branch information
Glen Tregoning authored and flovilmart committed Nov 20, 2016
1 parent 4ea455b commit 1eff210
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
50 changes: 49 additions & 1 deletion spec/MongoStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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();
});
});
});
2 changes: 1 addition & 1 deletion src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1eff210

Please sign in to comment.