Skip to content

Commit 1eff210

Browse files
Glen Tregoningflovilmart
authored andcommitted
MongoStorageAdapter.findOneAndUpdate returns Parse Object (#3053) (#3064)
1 parent 4ea455b commit 1eff210

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

spec/MongoStorageAdapter.spec.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
149149
});
150150
});
151151

152-
it('handles array, object, date', (done) => {
152+
it('handles creating an array, object, date', (done) => {
153153
let adapter = new MongoStorageAdapter({ uri: databaseURI });
154154
let obj = {
155155
array: [1, 2, 3],
@@ -189,4 +189,52 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
189189
done();
190190
});
191191
});
192+
193+
it("handles updating a single object with array, object date", (done) => {
194+
let adapter = new MongoStorageAdapter({ uri: databaseURI });
195+
196+
let schema = { fields: {
197+
array: { type: 'Array' },
198+
object: { type: 'Object' },
199+
date: { type: 'Date' },
200+
} };
201+
202+
203+
adapter.createObject('MyClass', schema, {})
204+
.then(() => adapter._rawFind('MyClass', {}))
205+
.then(results => {
206+
expect(results.length).toEqual(1);
207+
let update = {
208+
array: [1, 2, 3],
209+
object: {foo: 'bar'},
210+
date: {
211+
__type: 'Date',
212+
iso: '2016-05-26T20:55:01.154Z',
213+
},
214+
};
215+
let query = {};
216+
return adapter.findOneAndUpdate('MyClass', schema, query, update)
217+
})
218+
.then(results => {
219+
let mob = results;
220+
expect(mob.array instanceof Array).toBe(true);
221+
expect(typeof mob.object).toBe('object');
222+
expect(mob.date.__type).toBe('Date');
223+
expect(mob.date.iso).toBe('2016-05-26T20:55:01.154Z');
224+
return adapter._rawFind('MyClass', {});
225+
})
226+
.then(results => {
227+
expect(results.length).toEqual(1);
228+
let mob = results[0];
229+
expect(mob.array instanceof Array).toBe(true);
230+
expect(typeof mob.object).toBe('object');
231+
expect(mob.date instanceof Date).toBe(true);
232+
done();
233+
})
234+
.catch(error => {
235+
console.log(error);
236+
fail();
237+
done();
238+
});
239+
});
192240
});

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class MongoStorageAdapter {
310310
const mongoWhere = transformWhere(className, query, schema);
311311
return this._adaptiveCollection(className)
312312
.then(collection => collection._mongoCollection.findAndModify(mongoWhere, [], mongoUpdate, { new: true }))
313-
.then(result => result.value);
313+
.then(result => mongoObjectToParseObject(className, result.value, schema));
314314
}
315315

316316
// Hopefully we can get rid of this. It's only used for config and hooks.

0 commit comments

Comments
 (0)