feat: Add $setOnInsert operator to Parse.Server.database.update (#8791)

This commit is contained in:
Manuel
2023-10-25 19:13:27 +02:00
committed by GitHub
parent fe02d3e8aa
commit f630a45aa5
3 changed files with 50 additions and 1 deletions

View File

@@ -254,6 +254,45 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
expect(obj.get('foo').test.date[0] instanceof Date).toBeTrue();
});
it('upserts with $setOnInsert', async () => {
const uuid = require('uuid');
const uuid1 = uuid.v4();
const uuid2 = uuid.v4();
const query = {
x: 1,
};
const update = {
objectId: {
__op: 'SetOnInsert',
amount: uuid1,
},
x: 1,
count: {
__op: 'Increment',
amount: 1,
},
};
await Parse.Server.database.update(
'MyClass',
query,
update,
{ upsert: true },
);
update.objectId.amount = uuid2;
await Parse.Server.database.update(
'MyClass',
query,
update,
{ upsert: true },
);
const q = new Parse.Query('MyClass');
const docs = await q.find();
expect(docs.length).toBe(1);
expect(docs[0].id).toBe(uuid1);
expect(docs[0].get('x')).toBe(1);
expect(docs[0].get('count')).toBe(2);
});
it('handles updating a single object with array, object date', done => {
const adapter = new MongoStorageAdapter({ uri: databaseURI });